Solved

Random number generator

Posted on 2002-04-13
1
206 Views
Last Modified: 2013-01-07
Is there a way to use a random timer to prevent a # from being loaded the same each time the program starts?
Here is the code I use:


// Pick the random numbers
 $picka = rand (0,9);
 $pickb = rand (0,9);
 $pickc = rand (0,9);
 $pickd = rand (0,9);

As it is, the numbers generate randomly, each time the page is refreshed, they are different. However, once the site has been left and returned to, the random numbers are generated in the same sequence. Is there a code like randomize timer that will prevent this?


0
Comment
Question by:rhankins
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 5

Accepted Solution

by:
andriv earned 25 total points
ID: 6938911
I have copied and pasted your code and I get different values when I refresh the value and with new browser sessions I still get different values in different order.

The first browser session I get is 1076, I then opened a new window, call the script and I got, 3584.

What is it your are trying to accomplish because you seed the rand with:

srand(time());
$picka = rand(0,9);

Or you can use the Mersenne Twister algorithm with:

mt_srand(time());
$picka = mt_rand(0,9);
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question