[erlang-questions] more random uniform

Jachym Holecek <>
Sun Oct 27 18:15:17 CET 2013


# Bengt Kleberg 2013-10-27:
> Would it be better to use seed(O,X,Y) than seed(X,Y,O)?
> Or should I multiply them larger?

Here's three attempts that look encouraging (note I can't really justify
their validity):

  %% A1 large modulo Prime1, A2 small module Prime2, A3 noisy.
  25> rp([begin random:seed(30269 - X, 30307 + X, erlang:phash2(X)), random:uniform(3) end || X <- lists:seq(1, 100)]).                  
  [1,3,2,3,3,3,3,2,1,3,3,1,3,2,3,1,3,1,1,2,1,3,3,1,1,3,2,1,2,
   3,2,1,1,3,2,1,1,3,3,2,3,1,3,3,2,2,1,1,1,1,3,3,2,2,3,3,3,2,2,
   2,3,1,2,1,3,3,3,3,1,2,1,1,2,3,3,2,2,3,2,2,3,3,2,1,2,1,3,1,1,
   1,1,1,3,1,3,2,3,1,3,3]

  %% All components quite large and noisy.
  26> rp([begin random:seed(erlang:phash2(X), erlang:phash2(X + 1), erlang:phash2(X + 3)), random:uniform(3) end || X <- lists:seq(1, 100)]).
  [2,2,2,1,3,3,2,1,1,1,1,2,2,2,3,3,3,1,3,2,3,2,1,2,1,3,3,1,1,
   3,1,2,3,1,1,3,2,3,1,2,1,3,1,2,2,2,1,3,1,1,1,3,3,2,1,2,2,1,3,
   2,1,3,2,2,2,2,3,1,3,3,2,3,3,1,3,2,1,1,1,2,2,2,2,2,1,1,1,3,1,
   2,3,2,1,2,2,1,2,3,2,1]

  %% Playing around with actual now() constant, avoiding phash2().
  27> rp([begin random:seed(1382, 896041, 690123 + (16384*X)), random:uniform(3) end || X <- lists:seq(1, 100)]).                            
  [3,2,3,2,1,2,1,3,1,3,1,3,2,3,2,1,2,1,2,1,3,1,3,2,3,2,3,2,1,
   2,1,2,1,3,1,3,2,3,2,3,2,1,2,1,3,1,3,1,3,2,3,2,1,2,1,2,1,3,1,
   3,1,3,2,3,2,1,2,1,2,1,3,1,3,2,3,2,3,2,1,2,1,3,1,3,1,3,2,3,2,
   3,2,1,2,1,3,1,3,1,3,2]

You seem to have two deterministic parameters available, that should
be handy. In the last case note that just incrementing A3, as now()
would, didn't work very well -- shifting by 16 bits helped.

HTH,
	-- Jachym


More information about the erlang-questions mailing list