forum

Home / DeveloperSection / Forums / Random number generator only generating one random number

Random number generator only generating one random number

Anonymous User147429-May-2013
Hi,

I have the following function:

//Function to get random number
public static int RandomNumber(int min, int max)
{
    Random random = new Random();
    return random.Next(min, max);
}

I'm trying as following

byte[] mac = new byte[6];
for (int x = 0; x < 6; ++x)
    mac[x] = (byte)(Misc.RandomNumber((int)0xFFFF, (int)0xFFFFFF) % 256);

If I step that loop with the debugger during run time I get different values (which is what I want). However, if I put a break point two lines below that code, all members of the "mac" array have equal value.

Please resolve my problem.
Thanks in advance. 


Updated on 29-May-2013
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By