Random Numbers

What are Random Numbers

Random numbers are a sequence of numbers in an un predictable order. Generally there are
  • Real Random numbers

  • and
  • Pseudo Random numbers

  • Real random numbers are generated as the result of real random experiments like tossing a coin, throwing a die, choosing a coin from a lot etc.
    However in case of computer programs, generating real random numbers are not preferable because of the practical diffuculties.
    so Pseudo random numbers are used for generating keys for encryptions and simulating real world scenarios in games etc.

    Pseudo random numbers are computer generated random numbers. They are generated as the function of some unpredictable properties of the system like the current milliseconds, etc.

    In c# the Random class is used for the purpose.

    The following code creates an object of the random class.
    Random r = new Random();

    Here the system clock will be used for the seed value. The seed value is the value usin which the a set of pseudo random numbers are generated.
    Whenever we use the same seed, the sequence generated will be the same.

    Random r = new Random(10);
    Here 10 is used as the seed.

    int n= r.next(25);

    The above code assigns a random number which is not greater than 25, to the variable n.

    int n1 = r.next(50,250);

    The above code assigns a random number between 50 and 250 to the variable n1.


    No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: