Technically, there is a
Next
method on the
Random
class which allows you to specify bounds for your random number.
Here:
Random.Next Method (Int32, Int32)[
^]
Beware!
- The first parameter (
minValue
) is inclusive, whereas the second (
maxValue
) is
exclusive.
It means that, if you want a number between 1 and 50, you would have to write:
Random r = new Random();
int randomNumber = r.Next(1, 51);
There subsists an issue, though: this will give you a random number, but will not assure you its uniqueness in any way.
For that, there still have been answered to you that the
Guid
struct is much more appropriate.
More informations here:
Guid Structure[
^]
Hope this helps.