Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.