Hi,
I have some problems when I generate random number. How can I generate random number which is not duplicate.
Ex... if I have interval (from 1 to 10) I want to generate all random numbers from 1 to 10 without duplicate.
3,4,1,6,2,9,0,5,8,7 not like 4,5,3,2,9,3,3,2,1,5
Have c# something like this. Or if have gauss random number generator it will be better.
Thanks
Velosity of number generator
4 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Niradhip ChakrabortyRank #428 · 5.8K pointsPosted Apr 9, 2009, 2:07 AM EDT
protected void Page_Load(object sender, EventArgs e) { int intreturnValue = RandomNumber(100000, 999999); } private int RandomNumber(int min, int max) { Random random = new Random(); return random.Next(min, max); }Gorgi Markovski4 pointsPosted Apr 9, 2009, 2:36 AM EDT
I try this before.
Or, I have one circle and I want to generate random pixel in the circle. I need random number that will generate non duplicate pixel. To fill the circle faster.
Thanks
aru v30 pointsPosted Apr 9, 2009, 3:56 AM EDT
Hi,
To generate a non duplicate random number, insert all the random number generated in to a hash table with the number as key.Each time when the random number generated check with the HashTable value,if it already exists go for next random number.
Thanks,
Aru
Niradhip ChakrabortyRank #428 · 5.8K pointsPosted Apr 9, 2009, 5:25 AM EDT
If you want to make sure there are no duplicate numbers, you must put each generated number in an array or array list. Every time you click the button you must loop through the generated numbers and compare them to the newly generated number. If there is a duplicate number you must generate another until it is unique.
or please check the following Article:
http://www.c-sharpcorner.com/UploadFile/nanujogi/GenerateUniqueNumberinCSharp12022005233031PM/GenerateUniqueNumberinCSharp.aspx