473,386 Members | 1,842 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

reproducible random number series

I need to generate reproducible random number series.

I've done the obvious - use mt_srand with the same seed. This supposedly
will create the same series every time.

Is this true? Its not working for me.

By the way, seeding mt_srand with different integers doesn't necessarily
produce different series. I've done a little testing and every pair of
consecutive even and odd numbers produces the same series. eg. seed 0 and 1
produce the same series, as does 10000 and 10001.

geoffair in xgmailx xcomx
Sep 4 '06 #1
4 2979

geoffp wrote:
I need to generate reproducible random number series.

I've done the obvious - use mt_srand with the same seed. This supposedly
will create the same series every time.

Is this true? Its not working for me.

By the way, seeding mt_srand with different integers doesn't necessarily
produce different series. I've done a little testing and every pair of
consecutive even and odd numbers produces the same series. eg. seed 0 and 1
produce the same series, as does 10000 and 10001.

geoffair in xgmailx xcomx
As of PHP 4.2.0, there is no need to seed the random number generator
with srand() or mt_srand() as this is now done automatically.

I assume you want the same series of random numbers ?
If this is the case generate your series and save to a file

Sep 4 '06 #2
"geoffp" <fw*****@jhgjhfggb.comwrote:
>I need to generate reproducible random number series.

I've done the obvious - use mt_srand with the same seed. This supposedly
will create the same series every time.

Is this true? Its not working for me.
Really? I did this:

<?php
mt_srand(1000);
echo mt_rand(), "\n";
echo mt_rand(), "\n";
echo mt_rand(), "\n";
echo mt_rand(), "\n";
?>

and it produces the same sequence every time. Note that you can't rely on
the sequence continuing across pages.
>By the way, seeding mt_srand with different integers doesn't necessarily
produce different series. I've done a little testing and every pair of
consecutive even and odd numbers produces the same series. eg. seed 0 and 1
produce the same series, as does 10000 and 10001.
You are correct. The code for mt_srand always sets the bottom bit.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Sep 5 '06 #3

"Tim Roberts" <ti**@probo.comwrote in message
news:v8********************************@4ax.com...
"geoffp" <fw*****@jhgjhfggb.comwrote:
>>I need to generate reproducible random number series.

I've done the obvious - use mt_srand with the same seed. This supposedly
will create the same series every time.

Is this true? Its not working for me.

Really? I did this:

<?php
mt_srand(1000);
echo mt_rand(), "\n";
echo mt_rand(), "\n";
echo mt_rand(), "\n";
echo mt_rand(), "\n";
?>

and it produces the same sequence every time. Note that you can't rely on
the sequence continuing across pages.
>>By the way, seeding mt_srand with different integers doesn't necessarily
produce different series. I've done a little testing and every pair of
consecutive even and odd numbers produces the same series. eg. seed 0 and
1
produce the same series, as does 10000 and 10001.

You are correct. The code for mt_srand always sets the bottom bit.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Thanks Tim - I think I see whats happening.

I assumed that once srand had been seeded, the series would continue for
the whole session(I set it in the first page). From what you say I gather
that the series ends whenever you call a page, even though its got the same
PHP code. Then the randomiser is seeded automatically the first time its
called - DOH!

Geoff
Sep 5 '06 #4

"Tim Roberts" <ti**@probo.comwrote in message
news:v8********************************@4ax.com...
"geoffp" <fw*****@jhgjhfggb.comwrote:
....
>
and it produces the same sequence every time. Note that you can't rely on
the sequence continuing across pages.
>>By the way, seeding mt_srand with different integers doesn't necessarily
produce different series. I've done a little testing and every pair of
consecutive even and odd numbers produces the same series. eg. seed 0 and
1
produce the same series, as does 10000 and 10001.

You are correct. The code for mt_srand always sets the bottom bit.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Thanks Tim - I think I see whats happening.

I naively assumed that once srand had been seeded, the series would
continue for the whole session(I set it in the first page). From what you
say I gather
that the series ends whenever you call a page, even though its got the same
PHP code. Then the randomiser is seeded automatically the first time its
called - DOH!

Geoff

PS Some of my posts to this group don't seem to be appearing, so apologies
if you've got this twice. I don't often use newsgroups.

Sep 5 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: Paul Rubin | last post by:
http://www.nightsong.com/phr/python/sharandom.c This is intended to be less predicable/have fewer correlations than the default Mersenne Twister or Wichmann-Hill generators. Comments are...
13
by: quickcur | last post by:
Suppose I have a function rand() that can generate one integer random number between 0 and 100. Suppose also rand() is very expensive. What is the fastest way to generate 10 different random number...
5
by: user | last post by:
Hello i call it in almost same time (from two different threads): Random rand = new Random(); id=rand.Next(65535); and i often receive the same results. Is it possible ? How windows count this...
10
by: Curt_C [MVP] | last post by:
If I use it in my page it's fine but when I put it in a Class file for calling it returns the same # for each call. Any ideas why? I'm sure it's something I'll slap myself for but the only samples...
1
by: TCORDON | last post by:
How can i tell VB.NET to pick a random number from a predefined series like: 10,10,10,38,38,17,17,17,17,92 TIA
28
by: Elfour | last post by:
In c++ what is the code to make teh program randomly select a number?
21
by: chico_yallin | last post by:
I just wana make a random id number based on4 digits-for examples?? Thanks in Advance Ch.Yallin
34
by: Johannes Baagoe | last post by:
About Math.random(), ECMA 262 just says "Returns a number value with positive sign, greater than or equal to 0 but less than 1, chosen randomly or pseudo randomly with approximately uniform...
16
by: raylopez99 | last post by:
For the public record. RL public void IterateOne() { Random myRandom = new Random(); //declare Random outside the iteration for (int j = 0; j < Max; j++) {
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.