"Dr J R Stockton" <reply0938@newsgroup> wrote in message
news:GXaxBoHiyRtKFwrM@newsgroup
> In microsoft.public.scripting.vbscript message <35D5C1C2-B163-4439-82E5-
> 7591B1BB0662@newsgroup>, Thu, 17 Sep 2009 18:49:01, kaymaf
> <kaymaf@newsgroup> posted:
>
>> Can someone help me convert the code below to vbscript or any idea how
>> to
>>generate random number as string (at least 16 digits). I'm not sure what the OP had in mind by suggesting that the number be "at
least" 16 digits in length. You can almost safely assume that asking a
person to pick a number between 1 and 10 will result in as random a number
as humanly possible. Asking for one with at least 16 digits would be like
asking a person to pick a number with at least two digits (which would, in
turn, be like asking him to "pick a number between 10"). Since the highest
allowable number is not known, the results of a large number of samples from
a variety of volunteers would undoubtedly display a distribution across the
solution space that is definitely not uniform.
Another issue is that even 16-digit numbers with truly random "values" may
not necessarily exhibit digit "sequences" that appear truly random.
Certainly, if enough samples are taken, then the relative frequency of
numbers with non-random digit sequences (such as 1111111111111111,
2222222222222222, 3434343434343434, 1234567812345678, etc) would likely be
so low that one would have difficulty in accepting them as "random".
It seems to me that what is being asked for is more like a sequence of 16
random digits than an actual "random number". If that is the case, then a
better approach may be to use RND in a loop to select each digit in some
random fashion, and concatenate them into the resultant string.
I suspect that it might be difficult to determine which of two 16-digit
number sequences was generated by this method versus the "numeric" approach,
but it should be clear that the nature of the sequences is completely
different. It could possibly by dangerous, for example, to use the numeric
values of randomly selected digits in a situation where a sequence of random
numbers is actually a requirement.
But perhaps we are putting the cart before the horse, unless we consider
what the OP meant by "a random number". This term has been used to mean any
of the following:
- the least likely number that one might imagine
- a number not dependent on anything else
- a number selected completely at random (circular definitions are
wonderful)
- a number that looks random (i.e. numbers like 7777 are considered by
some as not being random, even though when expressed in hexadecimal no such
pattern would be present: 1E61. Then there are "random-looking" numbers like
65535 which, when displayed in hex (FFFF) have that non-random-appearing
pattern).
And the term "a sequence of random numbers" has been understood as a
sequence of numbers:
- in which none are repeated
- in which repeats are only allowed after all possible numbers have been
generated
- which, if repeats are allowed, they will never be successive (i.e.
this would not be allowed: 1 8 3 5 5 6 2)
- in which no patterns are discernible (by whom, I wonder)
- in which no sequences ever repeat.
> Be aware that the random number generator provided may well not have
> enough internal states to sustain a fully-random choice of 16 decimal
> digits. I agree that the precision issue is a definite concern.
But even in those cases where the precision is not an issue, the result is
still not necessarily "fully random". RND is not a "random number generator"
but a "pseudo random number generator". See
<URL"http://en.wikipedia.org/wiki/Random_number_generation#.22True.22_random_numbers_vs._pseudorandom_numbers>.
The really cool thing about pseudo-random numbers is that, although not
"truly random", they are extremely useful in approximating true randomness
when dealing with phenomena that are not deterministic in nature.
/Al
> See <URL:http://www.merlyn.demon.co.uk/vb-maths.htm#Rand>, which
> demonstrates that the results of Rnd are given by
> X[n+1] = ( X[n] * 16598013 + 12820163 ) mod 16777216
> followed by division by 16777216 = 2^24.
>
> That gives mediocre performance.
>
> If quality matters, look for VBScript KISS, after having read
> <URL:http://www.merlyn.demon.co.uk/js-randm.htm#Rand>.
>
> --
> (c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE7 FF3 Op9
> Sf3
> news:comp.lang.javascript FAQ
> <URL:http://www.jibbering.com/faq/index.html>.
> <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.