Jump to content

Random numbers


Yesideez

Recommended Posts

The "Weighted Rand" topic reminded me of something I've needed but never found.

 

I'm looking for a routine that will pick random numbers out between X and Y.

 

Here's the snag: no number may be called more than once and the routine needs to exit when all numbers between X and Y (inclusive) have been chosen.

 

I need this for both a basic number range and for a 2D array.

 

Any help appreciated :)

Link to comment
https://forums.phpfreaks.com/topic/131542-random-numbers/
Share on other sites

That would be good for a small range of numbers but when we're looking at a very large range the routine could pause a little too long towards the end.

 

I've seen what I need in action elsewhere (handy to fade out pictures for example using this random selection routine via 2D arrays) but I can't for the life of me figure out how to code it!

Link to comment
https://forums.phpfreaks.com/topic/131542-random-numbers/#findComment-683219
Share on other sites

It depends on how you're planning on using this. One possible way is to use rand(); and use a MySql database to save the created values, then check if they've been made before.

 

Rand works like this:

 

rand(5, 15);

 

That chooses a random number between 5 and 15.

Link to comment
https://forums.phpfreaks.com/topic/131542-random-numbers/#findComment-683224
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.