C # / XNA pseudo random number creation

The C # / XNA process for generating random numbers is pretty quick and easy, however, perhaps this is the worst random number generator I've ever seen. Is there a better way that is easy to implement for C # / XNA?

rand.Next () just doesn't fit my needs.

from

static private random rand = new Random ();

I accidentally put objects throughout my program. sometimes 10, sometimes 200.

When calling random objects (x val and y val are both random on the 2d plane), they are grouped. The generation code is clean and calls it good, a clean repeat is performed and pulls out a new random number with each value. But they are grouped, noticeably bad, which is not very good with random numbers in the end. I'm an intermediate skill with C #, I switched from as3, which seemed to handle randomness better.

I know well that they are pseudo-random, but C # on a Windows system is a grotesque grouping.

+5
source share
3 answers

Can you use System.Security.Cryptography.RandomNumberGenerator from XNA?

var rand = RandomNumberGenerator.Create();
byte[] bytes = new byte[4];

rand.GetBytes(bytes);

int next = BitConverter.ToInt32(bytes, 0);

min/max:

static RandomNumberGenerator _rand = RandomNumberGenerator.Create();

static int RandomNext(int min, int max)
{
    if (min > max) throw new ArgumentOutOfRangeException("min");

    byte[] bytes = new byte[4]; 

    _rand.GetBytes(bytes);

    uint next = BitConverter.ToUInt32(bytes, 0);

    int range = max - min;

    return (int)((next % range) + min);
}
+2

, System.Random. , Random , Random, , , ( .) Random .

, , , , System.Random.

+1

All Articles