[erlang-questions] beginner question
Ron Peterson
rpeterso@REDACTED
Sun Aug 17 05:07:12 CEST 2008
When I compile the code below and run it, I get something like the
following:
54> scrap:random_tuples( 20, 5 ).
[{3,9},{3,9},{3,9},{3,9},{3,9}]
I'm sure this is expected behaviour. I'm just not yet familiar enough
with erlang to understand it. Why isn't this the same as calling
random_tuple a number of times in succession?
TIA.
set_seed_to_now() ->
{A1, A2, A3} = now(),
random:seed( A1, A2, A3 ).
for( Max, Max, F ) ->
[F];
for( I, Max, F ) ->
[F|for( I+1, Max, F )].
random_tuple( Max ) ->
{ random:uniform( Max ), random:uniform( Max ) }.
random_tuples( Max, Num ) ->
set_seed_to_now(),
for( 1, Num, random_tuple( Max ) ).
--
Ron Peterson
Network & Systems Manager
Mount Holyoke College
http://www.mtholyoke.edu/~rpeterso
-
I wish my computer would do what I want it to do - not what I tell it to do.
More information about the erlang-questions
mailing list