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

后端 未结 6 1910
深忆病人
深忆病人 2020-12-17 15:38

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.

6条回答
  •  感动是毒
    2020-12-17 16:23

    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.

提交回复
热议问题