Random numbers

661 views
Skip to first unread message

raks

unread,
Mar 13, 2011, 12:00:32 PM3/13/11
to AMPL Modeling Language
Hi

I want to gain 10 random numbers between 0-30 but i don't want them to
be the same. I have written this in my script file.

set temp:=1..10;
param choice{temp};

for{i in temp}
let choice[i]:=ceil(Uniform(0,30));

However with what I have written I sometimes get the same number
multiple times.
Please help!

Thanks,
Rakesh

Jerry Shaw

unread,
Mar 13, 2011, 3:13:23 PM3/13/11
to am...@googlegroups.com
Well, that's why they call them random numbers.  Assuming the random number generator works right, you have a roughly 10% chance of drawing the same number twice if you're sampling a population of 30 numbers 10 times with replacement.

If you think of x as a specific number and n as the cardinality of the set,
for the first draw: P(x) = (1/n).  Then the prob of not getting the same number again is P(x<>the first number)=(1/(n-1)).  Assuming the draws are independent, the likelihood of not getting a repeat over a number of draws diminishes rapidly.

That's why Russian Roulette isn't a game you want to play often.  

If you want to check a solution over a range of values, you can uniformly generate the values for the variables you're interested in, solve,  and check the results.

JS


--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to am...@googlegroups.com.
To unsubscribe from this group, send email to ampl+uns...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ampl?hl=en.


Paul

unread,
Mar 13, 2011, 4:28:43 PM3/13/11
to am...@googlegroups.com
set POOL ordered default 1..30;
set INDEX := 1..10;
param choice {INDEX};
for {i in INDEX} {
  let choice[i] := member(ceil(Uniform(0, card(POOL))), POOL);
  let POOL := POOL diff {choice[i]}; 
}
display choice;

Paul
Reply all
Reply to author
Forward
0 new messages