Re: random numbers

new topic     » goto parent     » topic index » view thread      » older message » newer message

Allen Ashby wrote:
> 
> I am trying to generate 52 random numbers 1-52 without duplicating any
> numbers.
> it seems every time I try I get duplications. Does anyone have a
> solution for this.

Start with a sequence {1..52} and pull them from that.

s = {1,2,3,4,5,6,7,8,9,...52}
n = {}
for t=1 to 52 do
   r = rand(length(s)) -- grab a random position
   n &= s[r] -- add it to our new sequence
   s = s[1..r-1] & s[r+1..$] -- remove from available numbers
end for

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu