RubenPieters

Random RandomKaart = new Random();

int RandomKaartInt = RandomKaart.Next(1, 16);

int[] RandomXLocationIntArray = new int[] { 971, 996, 1021, 1046, 1071 };

Random RandomXLocation = new Random();

int IndexRandomXLocation = RandomXLocation.Next(RandomXLocationIntArray.Length);

int RandomXLocationInt = RandomXLocationIntArray[IndexRandomXLocation];

I have these 2 random numbers, and then a switch(RandomKaartInt) with cases from 1 to 15 and in those cases it makes the card come at new System.Drawing.Point(RandomXLocationInt, 510); but the first 3(case 1 to 3) cards always seem to come at x location 971, the second 3(case 4 to 6) cards at 996 and so on...

but what I want is that it comes at a totally random location, that the first 3 cards also can come at x location 996, 1021, 1046 and 1071 but not only 971

Does someone know how to fix this

thx in advance,

Ruben



Re: Visual C# Express Edition Random is not that random

JohnWein

You only need one instance of the Random class. Use it throughout your class.

Code Snippet

private Random RandomGen = new Random();

private void UseRandom()

{

int RandomKaartInt = RandomGen.Next(1, 16);

int[] RandomXLocationIntArray = new int[] { 971, 996, 1021, 1046, 1071 };

int IndexRandomXLocation = RandomGen.Next(RandomXLocationIntArray.Length);

int RandomXLocationInt = RandomXLocationIntArray[IndexRandomXLocation];

}





Re: Visual C# Express Edition Random is not that random

RubenPieters

that solved my problem, thanks Smile



Re: Visual C# Express Edition Random is not that random

IsshouFuuraibou

You may also want to look into things like Poisson distribution for random numbers. Especially if you need to skew or unskew randomization. You can use distribution equations to solve the problem of generating probabilities (unequal probabilities too).


One issue with Random is that if you wanted to, you can always have the same random numbers generated by using a seed (this is useful in some cases).

Most likely, the second Random was getting seeded (it needs to happen, but if you don't specify what seed, it will seed randomly) with the same seed, for whatever reasons.





Re: Visual C# Express Edition Random is not that random

JohnWein

If you define new Randoms within the same time slice, they all get the same seed.