yurchenkons
yurchenkons

Reputation: 143

Erlang random:seed() undefined

Every time I whant to get random seed, firstly i got "undefined", and then what i want.

1>random:seed(erlang:now()).
undefined

what's wrong?

another proof:1

Upvotes: 0

Views: 605

Answers (1)

Ahmad Sherif
Ahmad Sherif

Reputation: 6223

Because random module stores the seed value in the process dictionary using the put BIF. put returns the current value associated with the key (random module uses "random_seed"), so the first time you call seed there's no value associated with the key "random_seed" so it returns undefined, and on subsequent calls, it returns the current value, hence the values you're getting.

Example:

1> put(foo, "bar").
undefined
2> put(foo, "baz").
"bar"

Upvotes: 8

Related Questions