A
A
Andrew KreeZ2020-10-01 21:33:22
C++ / C#
Andrew KreeZ, 2020-10-01 21:33:22

Can't generate 3 random numbers, why?

Unable to generate 3 random numbers ( They are always the same ):

num11 = new Random().Next(0, 255);
num12 = new Random().Next(1, 254);
num13 = new Random().Next(2, 253);

Give a way to generate 3 completely different numbers per clock! Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew KreeZ, 2020-10-01
@guest_default

Everything worked when I changed the code to:

Random random = new Random();
int num11 = random.Next(0, 255);
int num12 = random.Next(0, 255);
int num13 = random.Next(0, 255);

Perhaps the error was in the compiler (dnSpy) and he did not want to make a random number directly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question