T
T
TheTalion2016-11-07 11:51:19
C++ / C#
TheTalion, 2016-11-07 11:51:19

Is there a simple multi-threaded random number generator with a given dimension in C#?

Of those that I found - RandomNumberGenerator ( https://msdn.microsoft.com/ru-ru/library/system.se... , works well, but not quite - it cannot be given a size, so it selects a random number from the entire space int For example, this code will return a number from -2,147,483,648 to 2,147,483,647, and size limiters cannot be selected.

public static int RandomNumber()
    {
      var bytes = new byte[4];
      var rmg = RandomNumberGenerator.Create();
      rmg.GetBytes(bytes);
      var returnValue = BitConverter.ToInt32(bytes, 0);
      Console.WriteLine("" + returnValue);
      return returnValue;
    }

Are there any ready-made multi-threaded random number generators in c#?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
GavriKos, 2016-11-07
@TheTalion

What prevents most to make an intervall? In general, Random is most often from 0 to 1, and fitting into the interval is already subsequent mathematical manipulations that have nothing to do with random - just sugar.

S
Spetros, 2016-11-07
@Spetros

If you want to learn programming yourself, you need to write labs yourself and not look for ready-made solutions.

D
Dmitry Bashinsky, 2016-11-11
@BashkaMen

int RandomNumber(int min, int max)
{
var r = new Random();
return r.Next(min, max);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question