473,800 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3012

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*****@jhgjhf ggb.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.com wrote in message
news:v8******** *************** *********@4ax.c om...
"geoffp" <fw*****@jhgjhf ggb.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.com wrote in message
news:v8******** *************** *********@4ax.c om...
"geoffp" <fw*****@jhgjhf ggb.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
3711
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 appreciated.
13
4238
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 between 0 and 100? (call rand() only 10 times...) Thanks, qq
5
2218
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 random ? Thanx
10
1659
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 I can find are for calling the Random() within the page, not a seperate class. --Page-- myClass myclass = new myClass(); for(int i = 1;i <= 100; i++) {
1
1859
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
2597
by: Elfour | last post by:
In c++ what is the code to make teh program randomly select a number?
21
13517
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
4114
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 distribution over that range, using an implementation-dependent algorithm or strategy." This is not good enough for my purposes (to generate identifiers with sufficient entropy, say 256 bits or so, to effectively preclude any chance of any two calls...
16
2085
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
10505
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10253
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10035
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9090
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7580
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6813
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.