Actual Random number generation - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Actual Random number generation

Allan#Allan# Posts: 2Member
I would like to generate a random number.
Currently im using the folowing:

using System;

private void GeraPadraoProjetado()
{
int i;
int seed = 2; //chosen randomly by me
Random fixRand = new Random(seed);

for(i=0;i<300;i++)
{
PadraoProjetado[i] = (int)(256*fixRand.NextDouble());
}
}

As I have observed, the generated numbers are always the same each time I execute the program.

When I programed in Visual Basic, I remember we had to use the "Randomize()" function before using the function that generated the random numbers in order to essure that the numbers would be actualy random.

Does anyone know what to do in C#?
Thanks in advance!]

Ps.: Excuse me about the code indentation, I simply didnt know how to do it here.



Comments

  • iwilld0itiwilld0it Posts: 1,134Member
    I usually use the the Environment.TickCount property because it is a constantly changing number:

    [code]
    using System;

    private void GeraPadraoProjetado()
    {
    int i;
    Random fixRand = new Random(Environment.TickCount);

    for(i=0;i<300;i++)
    {
    PadraoProjetado[i] = (int)(256*fixRand.NextDouble());
    }
    }
    [/code]
  • Allan#Allan# Posts: 2Member
    Thanks for the help!
    I will use it!

Sign In or Register to comment.