Skip to main content
added 3 characters in body
Source Link
Casperah
  • 4.6k
  • 1
  • 21
  • 13

If you want uniform distribution100 million unique random number you should createcould do something like this:

Now using Fisher-Yates suffle algorithm:

List<int> numbers = new List<int>(100000000); for (int i = 0; i < numbers.Capacity; i++) { numbersint rnd = random.AddNext(inumbers.Count + 1);   for(int i = 0; iif <(rnd == numbers.Count; i++Count) {  int rnd = random.Next( numbers.CountAdd(i); intelse  tmp = numbers[i]; { numbers[i] = numbers[rnd]; numbers.Add(numbers[rnd]);   numbers[rnd] = tmp;i; } } 

By the way you could calculate irNotFound much faster:

int irNotFound = irFirst - hsGenerated.Count; 

Good luck with your quest.

If you want uniform distribution you should create something like this:

List<int> numbers = new List<int>(100000000); for(int i = 0; i < numbers.Capacity; i++) numbers.Add(i);   for(int i = 0; i < numbers.Count; i++) {  int rnd = random.Next(numbers.Count); int tmp = numbers[i]; numbers[i] = numbers[rnd]; numbers[rnd] = tmp; } 

By the way you could calculate irNotFound much faster:

int irNotFound = irFirst - hsGenerated.Count; 

Good luck with your quest.

If you want 100 million unique random number you could do something like this:

Now using Fisher-Yates suffle algorithm:

List<int> numbers = new List<int>(100000000); for (int i = 0; i < numbers.Capacity; i++) { int rnd = random.Next(numbers.Count + 1); if (rnd == numbers.Count)  numbers.Add(i); else   {  numbers.Add(numbers[rnd]);   numbers[rnd] = i; } } 

By the way you could calculate irNotFound much faster:

int irNotFound = irFirst - hsGenerated.Count; 

Good luck with your quest.

added 3 characters in body
Source Link
Casperah
  • 4.6k
  • 1
  • 21
  • 13

If you want uniform distribution you should create something like this:

List<int> numbers = new List<int>(100000000); for(int i = 0; i < numbers.Count;Capacity; i++) numbers.Add(i); for(int i = 0; i < numbers.Count; i++) { int rnd = random.Next(numbers.Count); int tmp = numbers[i]; numbers[i] = numbers[rnd]; numbers[rnd] = tmp; } 

By the way you could calculate irNotFound much faster:

int irNotFound = irFirst - hsGenerated.Count; 

Good luck with your quest.

If you want uniform distribution you should create something like this:

List<int> numbers = new List<int>(100000000); for(int i = 0; i < numbers.Count; i++) numbers.Add(i); for(int i = 0; i < numbers.Count; i++) { int rnd = random.Next(numbers.Count); int tmp = numbers[i]; numbers[i] = numbers[rnd]; numbers[rnd] = tmp; } 

By the way you could calculate irNotFound much faster:

int irNotFound = irFirst - hsGenerated.Count; 

Good luck with your quest.

If you want uniform distribution you should create something like this:

List<int> numbers = new List<int>(100000000); for(int i = 0; i < numbers.Capacity; i++) numbers.Add(i); for(int i = 0; i < numbers.Count; i++) { int rnd = random.Next(numbers.Count); int tmp = numbers[i]; numbers[i] = numbers[rnd]; numbers[rnd] = tmp; } 

By the way you could calculate irNotFound much faster:

int irNotFound = irFirst - hsGenerated.Count; 

Good luck with your quest.

Source Link
Casperah
  • 4.6k
  • 1
  • 21
  • 13

If you want uniform distribution you should create something like this:

List<int> numbers = new List<int>(100000000); for(int i = 0; i < numbers.Count; i++) numbers.Add(i); for(int i = 0; i < numbers.Count; i++) { int rnd = random.Next(numbers.Count); int tmp = numbers[i]; numbers[i] = numbers[rnd]; numbers[rnd] = tmp; } 

By the way you could calculate irNotFound much faster:

int irNotFound = irFirst - hsGenerated.Count; 

Good luck with your quest.