Click here to Skip to main content
15,918,976 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hey there.

how can i get 3 unique numbers between 1 and 75 in vc#?

it is not homework just need some help on which method to use

// i have a program that should generate 3 random unique numbers that should be printed out on 3 different labels. (1st winner, 2nd winner, 3rd winner)

I already developed a solution but somethimes (not often) it ouputs 2 equal numbers

so is there any function or method that generates unique numbers everytime between a range eg. (1, 75)

ty all :)
Posted

1 solution

Have you tried something like this?

System.Random RandNum = new System.Random();
Label1.Text = RandNum.Next(1, 75).ToString();
Label2.Text = RandNum.Next(1, 75).ToString();
Label3.Text = RandNum.Next(1, 75).ToString();


croell wrote:
I already developed a solution but somethimes (not often) it ouputs 2 equal numbers


If you are generating random number there might be a chance that same number can be generated twice. But if you don't want that just store the generated random number in a array and make sure that each element of the array is unique before adding to it, if any number is already present in the array in that case generate a new number. Once you got all the number in the array assign these values to the desired labels.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900