Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2023-12-07 00:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (32 votes). Check out past polls.

    Notices?