| |

VerySource

 Forgot password?
 Register
Search
View: 10|Reply: 2

Random variable

[Copy link]

1

Threads

2

Posts

3

Credits

Newbie

Rank: 1

Credits
3

 China

Post time: 2020-3-23 23:30:01
| Show all posts |Read mode
using System;
class ThrowRoll
{
    public static void Main ()
    {
        int roll = 0;
        Random rnd = new Random (); // Please help me explain what Random means or usage? What I know is this sentence creates a variable that stores random numbers
        roll = (int) rnd.Next (1,7);
        Console.WriteLine ("Start the dice");
        Console.WriteLine ("This time the roll is: {0}", roll);
        switch (roll)
        {
            case 1:
            case 3:
            case 5:
                Console.WriteLine ("The dice is odd"); break;
            case 2:
            case 4:
            case 6:
                Console.WriteLine ("The dice is even"); break;
            default:
                Console.WriteLine ("Dice is not 1 ~ 6"); break;
        }
    }
}
Reply

Use magic Report

0

Threads

5

Posts

5

Credits

Newbie

Rank: 1

Credits
5

 China

Post time: 2020-7-3 23:45:01
| Show all posts
Random is a class, and here is just instantiating the class.
Random is a class for generating random numbers.
Then call the class method Next() to get a random number.
Class contains methods-initialize the class before calling the method
Reply

Use magic Report

1

Threads

2

Posts

3

Credits

Newbie

Rank: 1

Credits
3

 China

 Author| Post time: 2020-7-17 15:45:01
| Show all posts
thank you! ! !
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2020|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list