I have tried two different ways to get a sequence of random numbers:
// (a) works
Random random = new Random();
return Enumerable.Range(0, 20).OrderBy(n => random.Next());
// (b) does not work
return Enumerable.Range(0, 20).OrderBy(n => new Random().Next());
The first variant, where I am using random.Next()
, is working fine.
But the variant, where I have call new Random().Next()
, does NOT return random numbers; instead it returns a sequence of numbers from 0 to 20.
Now my questions are:
- What is term to denote the second type of initialization of object
new Random().Next()
in C#? - And how it is different from the first one so that I am not getting the desire output?