Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 905
Default Is there something wrong with the random generator in Excel?

"Rick Rothstein" wrote:
See the Note in the Remarks section of the Help Files for either the
Randomize or Rnd functions.


D'oh! I read EricG's explanation literally [1]. I spotted-checked the Help
page, but I did not look at all of the details.

Empirically, I discovered that Rnd -1 (any negative number) is also needed
in order for multiple calls to Randomize (no argument) to repeat the same
sequence of pseudorandom numbers when called within the same 15.625-msec
window. (System time is updated every 15.625 msec, at least in MSWin XP.)

Not very useful, of course. But that explains why calling Randomize alone
in a tight loop seemed to work suprisingly well, albeit not a good practice.

It appears that Randomize uses some state information (probably the PRNG
factors after the last Rnd call) in conjunction with its argument, or with
"system time" when there is no argument. Calling Rnd -1 first ensures a
consistent state, ergo a repeatable seed. Without calling Rnd -1
before Randomize, the PRNG state is inconsistent, resulting in an
unpredictable seed despite the same or similar "system time".


-----
[1] EricG wrote: ``If you are using something like "Randomize 1234568",
then you will get the same "random" numbers each time you run your code.``


----- original message -----

"Rick Rothstein" wrote in message
...
Let me be more clear. When "Randomize 123" is put into the ThisWorkbook
Workbook_Open macro, the first Rnd value is indeed the same each time the
workbook is opened.

But subsequent calls to "Randomize 123" result in different first Rnd
values, whether those calls are in Workbook_Open or in a public macro
like
testRandomize2 below.

Am I doing something wrong?(!)


See the Note in the Remarks section of the Help Files for either the
Randomize or Rnd functions.

--
Rick (MVP - Excel)


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I set up a random name generator in excel (school use) mochapo Excel Discussion (Misc queries) 5 April 2nd 23 07:40 PM
How do I create a random number generator in excel? Katie Excel Worksheet Functions 2 July 20th 06 01:50 AM
Can excel be used to create a random number generator? comotoman Excel Discussion (Misc queries) 2 September 16th 05 09:55 PM
Excel 2003 random number generator JJ Excel Discussion (Misc queries) 1 May 4th 05 01:02 PM
How do you create a random number generator in Excel? gmrobillard Excel Worksheet Functions 5 March 23rd 05 09:10 AM


All times are GMT +1. The time now is 06:43 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"