RNG seeding example from YAWS

Greg Perry Greg.Perry@REDACTED
Sun May 31 20:10:18 CEST 2009


Here is an RNG seeding example from YAWS (urandom.yaws), it looks like
the material for the RNG seed is derived from the current date and time
then hashed:

----------

<erl>
 
out(A) ->
    Self = self(),
    spawn(fun() ->
     %% Create a random number
     {_A1, A2, A3} = now(),
     random:seed(erlang:phash(node(), 100000),
       erlang:phash(A2, A3),
       A3),
     Sz = random:uniform(100000),
 
     %% Read random junk
     S="dd if=/dev/urandom count=1 bs=" ++
     integer_to_list(Sz) ++ " 2>/dev/null",
     P = open_port({spawn, S}, [binary,stream, eof]),
 
     rec_loop(Self, P)
   end),
    
    {streamcontent, "application/octet-stream", <<>>}.
 
      
rec_loop(YawsPid, P) ->
    receive
  {P, {data, BinData}} ->
   yaws_api:stream_chunk_deliver(YawsPid, BinData),
   rec_loop(YawsPid, P);
  {P, eof} ->
   port_close(P),
   yaws_api:stream_chunk_end(YawsPid),
   exit(normal)
    end.
 
 
</erl> 

----------

So given this example, would a process' seeding using random:seed()
affect any other running processes, or just the current process where
the seed was changed?  i.e. if there were 100 processes spawned, each of
which initially changes the random seed, would that seed only affect and
be used in conjunction with random:uniform() called from within that
current process?

Regards

Greg







More information about the erlang-questions mailing list