setting a variable using a random number from x to y

How can I set a variable using a random number from 1 to 10

------------------------------------------------------------------------------

For example if I have a variable named "a" in pascal , my code is :

a := random(1..10);

If I use this code in paccal "a" will be a number from 1 to 10(for example 1 or 4).

------------------------------------------------------------------------------

I need a code like that in c#.



Answer this question

setting a variable using a random number from x to y

  • TTLied

    Hi,
    in c# you have to create an instance of Random class and call a method:

    Random MyRandom = new Random();
    int num = MyRandom.Next(1, 11);

    The Next(min, max) method generates an integer number greater or equal than min and less than max.



  • Smartway

    Hi,

    Use following statement...

    Random rnd = new Random();
    int myNumber=rnd.Next(1, 4);


    Hope this help.



  • setting a variable using a random number from x to y