C generates a large number of non repeating random Numbers in a short time

  • 2020-05-09 19:06:10
  • OfStack

To generate random Numbers, Random can be used as a pseudo-random number generator, which is controlled by the seed to generate pseudo-random Numbers. By default, the current time value is taken as the seed. If the program is running fast, it will run multiple times at almost the same time. So if we're going to generate 5 random Numbers between 1 and 10, we're going to get 2, 2, 1, 1, 1, so how do we get very random Numbers that don't repeat themselves? Like 4, 2, 3, 3, 5.

Some people say Thread.Sleep (5), but I don't recommend it because it slows the system down.

The approach I took was to use the seed Guid.NewGuid ().GetHashCode () without a lot of repetition in a short time.

Related articles: