Jump to content

[SOLVED] How to randomly select a number from a discontinuous set of numbers ?


tmyonline

Recommended Posts

Hi guys:

 

Here's my problem:

 

    $expSQL    = "SELECT experiences_key FROM experiences_teachers_jn WHERE schools_key = $s";

    $expResult  = mysql_db_query($db,$expSQL,$cid);

    $expRow    = @mysql_fetch_assoc($expResult);

 

Because there are many "experiences_key" associated with a given schools_key (many-to-one relationship), after fetching the $expResult, the $expRow is a column of numbers.  I would like to randomly select a number from this list (column).  However, because these numbers do not form a continuous sequence, if I specify the lower bound and upper bound, there will be chances that the number selected is not on the list.  For example, $expRow could be {1, 5, 12, 21,..., 783}.

 

I was thinking of storing these values in an array and go from there but is there a better way to do this ?

 

Thanks.

Tommy

Link to comment
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.