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

后端 未结 6 1896
深忆病人
深忆病人 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:38

    Pseudorandom number generator from crypto module works better crypto:rand_uniform(From, To).
    To generate a 1000-element list with random numbers between 1 and 10:

    crypto:start(),
    [crypto:rand_uniform(1, 10) || _ <- lists:seq(1, 1000)].
    

提交回复
热议问题