Solved

Random number generator

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

815 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now