Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^2: How to generate different random numbers?

by Rhys (Pilgrim)
on Sep 05, 2004 at 00:52 UTC ( #388546=note: print w/replies, xml ) Need Help??

in reply to Re: How to generate different random numbers?
in thread How to generate distinct random numbers?

It might be more helpful to return shuffled ints between $start and $end, even if $num < $range. The user just won't get back $num ints. Perhaps the $range+1 returned value could be "Range too small."

As for shuffle vs. rand, "use Benchmark". :-) See if there's a predictable threshold where one overtakes the other.

Update: Is the ratio between $num and $range significant when determining whether a shuffle or rand is better to use? It would seems that a very small $num:$range ratio would benefit from rand, where shuffle-ing is better as $num:$range -> 1.

Or am I speaking from a non-standard orifice?

  • Comment on Re^2: How to generate different random numbers?

Replies are listed 'Best First'.
Re^3: How to generate different random numbers?
by ranjan_jajodia (Monk) on Sep 05, 2004 at 06:26 UTC
    hi johnnywang,
    As soon as you talk about 'distinct', 'random' goes out of the window. So i assume you need distinct numbers upon which you can't apply any pattern. The best way is to write a hash function on the current date + time which ofcourse must not give always increasing or decreasing numbers. Use google to find a suitable algorithm ( i am sure people have done it before).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://388546]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2020-11-30 09:14 GMT
Find Nodes?
    Voting Booth?

    No recent polls found