How to create a list of 1000 random numbers in Erlang?

USer22999299 picture USer22999299 · Apr 25, 2012 · Viewed 14k times · Source

I'm sure that there is a function for that. I just want to make a list of 1000 numbers, each one of them which should be random.

Answer

Adam Lindberg picture Adam Lindberg · Apr 25, 2012

To generate a 1000-element list with random numbers between 1 and 10:

[rand:uniform(10) || _ <- lists:seq(1, 1000)].

Change 10 and 1000 to appropriate numbers. If you omit the 10 from from the rand:uniform call, you'll get a random floating point number between 0.0 and 1.0.

On Erlang versions below 18.0: Use the random module instead. Caution! You need to run random:seed/3 before using it per process, to avoid getting the same pseudo random numbers.