Getting a *more* random value
Fredrik Thulin
ft@REDACTED
Wed Mar 29 10:08:18 CEST 2006
On Wednesday 29 March 2006 01:40, Pupeno wrote:
> Hello.
> I have an application where new processes are launched which
> calculate one random number between 0 and 512 and then do something
> with that number and terminate.
> I am currently using random:uniform(513) - 1 but that gives me the
> same random value for all the processes for each run of the
> application. I see that consecutive calls would get other numbers but
> I only need one. How am I supposed to get a number that is not the
> same on every process ? Thank you.
Seed the random generator with something that isn't the same when you
restart your application?
1> {A,B,C} = erlang:now(), random:seed(A, B, C).
undefined
2> random:uniform(513).
123
3>
restart
1> {A,B,C} = erlang:now(), random:seed(A, B, C).
undefined
2> random:uniform(513).
254
3>
/Fredrik
More information about the erlang-questions
mailing list