Solved

Random number generator

Posted on 2002-04-13
1
201 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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

728 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

9 Experts available now in Live!

Get 1:1 Help Now