Generating random number

Associate
Joined
5 Jun 2013
Posts
404
Hi there

i need help in generating 60 different random numbers
the first 20 numbers are between 1,10
the second 20 numbers are between 1,15
the third 20 numbers are between 1,20

this is for visual studio

so far when it created the first set of, it used for the second set and third and so on so does not work
 
what language?

Most languages have a random number generator but sometimes you need to give it a seed number before it works properly.
 
um you can just use the Random class in .net so if you wanted 3 sets of numbers increasing it'd be like

Code:
var rnd = new Random();

var firstSet = new List<int>();
var secondSet = new List<int>();
var thirdSet = new List<int>();

for (var i = 0; i < 20; i++)
{
  firstSet.Add(rnd.Next(10));
  secondSet.Add(rnd.Next(15));
  thirdSet.Add(rnd.Next(20));
}

or all in one list would be say

Code:
var rnd = new Random();
var fullList = Enumerable.Range(0, 60).Select(x => x < 20 ? rnd.Next(10) : x < 40 ? rnd.Next(15) : rnd.Next(20));

lots of ways to do it really
 
Visual Studio is an IDE, we need to know the language you're writing in.

That said, you want two loops. One to increment the max limit by 5 on each iteration, and one within that to fetch your 20 numbers.
 
Visual Studio is an IDE, we need to know the language you're writing in.

That said, you want two loops. One to increment the max limit by 5 on each iteration, and one within that to fetch your 20 numbers.

Or 1 loop with 3 calls, as above.

The other things do you want really random numbers, or pseudo random numbers? The latter is easy, the former is difficult without buying some expensive hardware.
 
Back
Top Bottom