Solved

Random number generator

Posted on 2002-04-13
1
204 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
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

680 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