Random function 2

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

How I get x items randomly from a sequence that has length y,
 where y > x, but no duplicate items in x?


 This function (untested):

 function getsome(object howmany, object y)
 object result, r
     result = {}
     for i=1 to howmany do
         r = rand(length(y))
         result = append(result, y[r])
         y = y[1..r-1] & y[r+1..length(y)]
     end for
     return result
 end function

 seems to be inefficient.

 Any suggestion?

 Thanks!

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

Search



Quick Links

User menu

Not signed in.

Misc Menu