10 random numbers unity

void Start(){   //having an int Array of 10 members   int [] numbers = new int[10];   //using a string variable to keep record of the used numbers   string usedNumbers ="-";   //cycle to get 10 random numbers   for (int i = 0 ; i<10; i++)   {      //get a random number between 0 - 120, 0 and 120 included on the random numbers      int randomNumber = Random.Range(0,121);      //Checking if the random number you get is unique, if you already have it in the string means that this random number is repeated, the "-X-" is to make the difference between the numbers, like -1- from -11-, if you dont have the "-X-" the 1 is in 21 and would be a "repeated" number      while(usedNumbers.Contains("-"+randomNumber.ToString()+"-"))      {         //if a number is repeated, then get a new random number         randomNumber = Random.Range(0,121);      }      usedNumbers+= randomNumber.ToString()+"-";      numbers[i] = randomNumber;   }}

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source