Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Random number generator

Posted on 2002-04-13
1
Medium Priority
?
208 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 100 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

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…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
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.

670 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