From the course: Advanced C#: Functional Programming Patterns
Unlock this course with a free trial
Join today to access over 24,800 courses taught by industry experts.
Specify a smaller range of random numbers - C# Tutorial
From the course: Advanced C#: Functional Programming Patterns
Specify a smaller range of random numbers
To review what we saw in the last video, I have a next method that takes a seed and returns a random result of int. That means that the random integer value I'm getting back is a positive integer from 0 to 2.1 million. That is a big range. There are many times when programming we don't need that big a range for our random number. Perhaps I want a range from 1 to 20. So what I've done is I've created another method on line 22 called Between. It also returns a random result of int. It has three parameters: the low value, the minimum, the high value, and a seed. In this example, I typed the seed as long because you can pass it along from the system clock or I could also pass an integer and that would also work. The code in here is taking the long value and making sure it's not bigger than an int because I have to pass an int into this method. Then on line 25, I'm calling next with this new seed that I have here, intSeed. Then I'm doing a calculation here to make sure the result's in this…