Re: VBScript Random Numbers and Letters

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



JRS: In article <ea77VoFdFHA.3156@xxxxxxxxxxxxxxxxxxxx>, dated Sat, 18
Jun 2005 18:01:37, seen in news:microsoft.public.scripting.vbscript,
Richard Mueller [MVP] <rlmueller-NOSPAM@xxxxxxxxxxxxxxxxxxxx> posted :
>
>Only call Randomize once, before the For/Next loop. I believe calling it
>more than once can make the sequence less random.

That advice is certainly good; but in a brief attempt I failed to make a
convincing demonstration in VBS on a local "Web" page and with cscript
at a DOS Prompt that doing otherwise is positively harmful.

In at least two languages, randomize loads the seed with something
permuted from the date/time, and hence will if called in a tight loop
load the same value repeatedly.

It occurs to me that by using
not seed = <scramble-time>
but seed = seed xor <scramble-time>
in the code of Randomize, the problem would not occur; perhaps VB does
this or similar ???

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
.



Relevant Pages

  • Re: ERROR IN AFONSO CODE
    ... So the three PRINT statements do an on-screen update, ... I'm surprised you didn't say anything about the use of "RANDOMIZE ... TIMER" inside the v loop. ...
    (sci.stat.math)
  • Re: Adding functions to generic package
    ... >> What do Randomize and Move do? ... How is that different from Splice? ... search for the iterator designating those nodes. ... > end loop; ...
    (comp.lang.ada)
  • Re: question: what does this "fix" thingy here do? r=fix(rnd*6)+1
    ... > You don't want to be using GoTo, especially to jump out of a loop like ... One way to avoid it would be to use another array to store ... > dim i as long ... > randomize ' only do this once in the application ...
    (microsoft.public.vb.general.discussion)
  • Re: how to generate random string?
    ... Randomize Second ... Loop Until Len= 20 ... any good solutions before i start writing something inefficient? ...
    (microsoft.public.scripting.vbscript)