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

Re^2: How to not print the same random number

by shotgunefx (Parson)
on Mar 04, 2006 at 11:01 UTC ( #534454=note: print w/ replies, xml ) Need Help??


in reply to Re: How to not print the same random number
in thread How to not print the same random number

While fine for small ranges, won't that be a hog on larger number ranges?
update I understand that the poster is only looking for 1-10, just seemed the better way to teach. Opinions?


-Lee
"To be civilized is to deny one's nature."


Comment on Re^2: How to not print the same random number
Re^3: How to not print the same random number
by borisz (Canon) on Mar 04, 2006 at 11:05 UTC
    Yes sure, the array with all numbers is build and shuffled. On the other hand, hash solutions require more memory and more cpu power they build the same array but slower. A hash is a better choice, if you use only some number out of a large range. For really really much numbers a database is my best choice.
    Boris
      That's what I figured. I haven't kept up lately, didn't know if some lazy evaluation had snuck in there ;)

      -Lee
      "To be civilized is to deny one's nature."
Re^3: How to not print the same random number
by fishbot_v2 (Chaplain) on Mar 04, 2006 at 15:30 UTC

    The question becomes "are you going to use all the numbers in that range?" If so, you have to remember them all regardless of your approach. If no, then you could save memory by just tracking what you use... but this then becomes more processor-expensive.

      On the plus side, once you've "bought it", the cost is pretty much constant.

      -Lee
      "To be civilized is to deny one's nature."
Re^3: How to not print the same random number
by ysth (Canon) on Mar 05, 2006 at 07:53 UTC
    Not much of a hog. Storing the numbers already picked in a hash would be about as bad. (I'm not sure how many copies of the list the shuffle approach will end up having.)

    But anyway, if you go with what I understand to be your idea of repeatedly generating random numbers until you find one not yet in a hash, you'll end up taking a very very long time finding the last few numbers if the limit is, say, 1000000.

      Well, I suppose I should have been more clear. I would think for many applications, the number of numbers picked compared to the number range would be relatively small.

      So I guess the proper answer would be, "it depends".

      -Lee
      "To be civilized is to deny one's nature."

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2014-08-23 09:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (173 votes), past polls