SLR1 Random Number generation Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

How does C sharp generate random numbers?

A

C# provides the Random class to generate random numbers based on the seed value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What would be some code to generate a random number?

A

Random rnd = new Random();
int num = rnd.Next();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What code would generate multiple random numbers?

A

Random rnd = new Random();

for (int j = 0; j < 4; j++)
{
Console.WriteLine(rnd.Next());
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What code would allow me t generate random numbers within a range. E.g., less than 10

A

Next(int)

e.g., Next(10)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What code would allow me t generate random numbers within a range. (maximum and minimum value)

A

Next(int min, int max)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to generate a random decimal number

A

NextDouble()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How is a seed value generated?

A

The Random class uses the seed value as a starting value for the pseudo-random number generation algorithm

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How des the random class work for seed values?

A
  • Random class uses the system clock to generate its seed value
  • This means that each instance of the Random class can generate different random numbers.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly