Re: Random NUmber Generator creates duplicates
From: Dr John Stockton (spam_at_merlyn.demon.co.uk)
Date: 10/23/04
- Next message: Nuno: "Change IE proxy"
- Previous message: Dr John Stockton: "Re: script to list objects in descending order by size and show path"
- Maybe in reply to: pldz: "Random NUmber Generator creates duplicates"
- Next in thread: Bob Barrows [MVP]: "Re: Random NUmber Generator creates duplicates"
- Reply: Bob Barrows [MVP]: "Re: Random NUmber Generator creates duplicates"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 23 Oct 2004 23:16:27 +0100
JRS: In article <OG9tA4PuEHA.3788@TK2MSFTNGP09.phx.gbl>, dated Sat, 23
Oct 2004 08:44:26, seen in news:microsoft.public.scripting.vbscript, Bob
Barrows [MVP] <reb01501@NOyahoo.SPAMcom> posted :
>Why should a random number generator avoid duplicates? Random numbers are,
>well, random, not unique. "random" and "unique" are mutually exclusive.
>Think about coin tosses. If your idea that all possible events have to occur
>before an event was duplicated was true, then nobody would ever throw two
>heads in a row. Every time you pick from a list of possible outcomes, every
>item in that list has an equal chance of being picked, given that the choice
>algorithm has no "memory".
>
>The only way to guarantee uniqueness is to either:
>1. Store all possible outcomes and remove an outcome from the list when it's
>chosen until the list count reaches zero (or some arbitrary limit)
>2. Store all chosen outcomes and compare each new choice to the list before
>accepting it.
What we are discussing is, however, a pseudo-random number generator;
there are various types.
They will cycle through all accessible internal values, and then repeat
that sequence indefinitely.
In Borland Pascal and Delphi, for example, the generator has a 32-bit
seed and uses S' := (n*S + 1) mod 2^32 ; - the seed itself is
accessible, and cycles through all 2^32 possibilities in a nearly-
arbitrary looking order before repeating.
In VBS, using Randomize N, what is the proper range of N? 0<=N<1.0,
integer, dword, or other? And can the current seed be read back?
If the VB generator is of similar form, it may be possible to deduce its
algorithm and re-implement in VB, so that the seed is accessible; it
should be possible to implement the Pascal one (caution - choice of a
good N is non-trivial - see Knuth).
<URL:http://www.merlyn.demon.co.uk/pas-rand.htm> has more.
-- © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. © <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links; <URL:http://www.merlyn.demon.co.uk/clpb-faq.txt> RAH Prins : c.l.p.b mFAQ; <URL:ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.
- Next message: Nuno: "Change IE proxy"
- Previous message: Dr John Stockton: "Re: script to list objects in descending order by size and show path"
- Maybe in reply to: pldz: "Random NUmber Generator creates duplicates"
- Next in thread: Bob Barrows [MVP]: "Re: Random NUmber Generator creates duplicates"
- Reply: Bob Barrows [MVP]: "Re: Random NUmber Generator creates duplicates"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|