Hello,

rnd() is not random (on my computer)

Does anyone has an option for generating random numbers? I need random
numbers between 0 and a million (1000000)

Thanx,

Marco L.
(my script runs every 30 seconds) maybe I have to do something with the
time!!

Re: RND not random by Anthony

Anthony
Fri Dec 08 10:24:52 CST 2006


"Marco J.L." <luyenews@yahoo.com.news> wrote in message
news:%23jD7cFuGHHA.924@TK2MSFTNGP02.phx.gbl...
> Hello,
>
> rnd() is not random (on my computer)
>
> Does anyone has an option for generating random numbers? I need random
> numbers between 0 and a million (1000000)
>
> Thanx,
>
> Marco L.
> (my script runs every 30 seconds) maybe I have to do something with the
> time!!
>

Yes that's exacty what happens if you use the statement:-

Randomize

Before trying to generate a sequence from rnd()

RTM:-

http://msdn.microsoft.com/library/en-us/script56/html/ac1ef1bb-f1d8-4369-af7f-ddd89c926250.asp



Re: RND not random by Richard

Richard
Fri Dec 08 10:27:23 CST 2006

Marco J.L. wrote:

> rnd() is not random (on my computer)
>
> Does anyone has an option for generating random numbers? I need random
> numbers between 0 and a million (1000000)

Did you initialize the seed for the psuedo random number generator with the
Randomize command? This seeds the generator with a value from the system
clock. For example:
=========
Randomize
For k = 1 To 10
x = Int(Rnd * 1000000)
Wscript.Echo x
Next
=========
This will produce a different sequence each time it is run. If you want to
generate the same sequence each time, seed the generator with a specified
value. For example:

Randomize(.5)

will result in the same sequence each time.

No computer generated sequence is truely random, but the Rnd function is
better than most. It is based on a maximal length 24-bit linear congruential
generator, which is about as good as you can do in VBScript without going to
great lengths to avoid overflow errors.

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net



Re: RND not random by Marco

Marco
Fri Dec 08 11:06:10 CST 2006

Why do I always get the same output when I run the script again?




"Richard Mueller" <rlmueller-NOSPAM@ameritech.NOSPAM.net> wrote in message
news:%233gG$WuGHHA.4920@TK2MSFTNGP05.phx.gbl...
> Marco J.L. wrote:
>
>> rnd() is not random (on my computer)
>>
>> Does anyone has an option for generating random numbers? I need random
>> numbers between 0 and a million (1000000)
>
> Did you initialize the seed for the psuedo random number generator with
> the Randomize command? This seeds the generator with a value from the
> system clock. For example:
> =========
> Randomize
> For k = 1 To 10
> x = Int(Rnd * 1000000)
> Wscript.Echo x
> Next
> =========
> This will produce a different sequence each time it is run. If you want to
> generate the same sequence each time, seed the generator with a specified
> value. For example:
>
> Randomize(.5)
>
> will result in the same sequence each time.
>
> No computer generated sequence is truely random, but the Rnd function is
> better than most. It is based on a maximal length 24-bit linear
> congruential generator, which is about as good as you can do in VBScript
> without going to great lengths to avoid overflow errors.
>
> --
> Richard
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
>



Re: RND not random by Richard

Richard
Fri Dec 08 11:58:54 CST 2006

If you are using the Randomize function (with no parameters) and still
getting the same sequence each time, that is strange. I cannot duplicate
that. I'd like to know what OS your script is running under.

I've studied the Rnd function and actually figured out the Linear
Congruential Generator used. I could give you the code for this, or a
similar generator, but you would have the same problem, how to seed it with
a random value that will result in a different sequence each time it is run.
I studied the Randomize function, but was never able to figure it out. It is
supposed to seed Rnd with a value from the system clock. While Rnd only
outputs numbers between 0 and 1, you can pass any value to Randomize. One
solution for you would be to use the output from the Timer function, which
is the number of seconds since midnight (to the nearests 100th of a second).
For example:
================
y = Timer
Randomize y
For k = 1 To 10
x = Int(Rnd * 1000000)
Wscript.Echo x
Next
================
If you are worried about the chance of generating the same sequence at the
same time each day, you could add in the current date. The Date function
returns the number of days since 12/30/1899. Perhaps:
==========
y = Timer
z = Date
Randomize y + z
==========
Or, you could somehow retain a sequential number to seed the generator,
incrementing it each time the script runs. The way psuedo random number
generators work, you will still get completely different sequences. For
example, to demonstrate:
============
For j = 101 To 105
' The next number in the sequence seeds the generator each day.
Randomize j
For k = 1 To 10
x = Int(Rnd * 1000000)
Wscript.Echo j & ": " & x
Next
Next

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net

"Marco J.L." <luyenews@yahoo.com.news> wrote in message
news:u3KkrsuGHHA.1784@TK2MSFTNGP06.phx.gbl...
> Why do I always get the same output when I run the script again?
>
>
>
>
> "Richard Mueller" <rlmueller-NOSPAM@ameritech.NOSPAM.net> wrote in message
> news:%233gG$WuGHHA.4920@TK2MSFTNGP05.phx.gbl...
>> Marco J.L. wrote:
>>
>>> rnd() is not random (on my computer)
>>>
>>> Does anyone has an option for generating random numbers? I need random
>>> numbers between 0 and a million (1000000)
>>
>> Did you initialize the seed for the psuedo random number generator with
>> the Randomize command? This seeds the generator with a value from the
>> system clock. For example:
>> =========
>> Randomize
>> For k = 1 To 10
>> x = Int(Rnd * 1000000)
>> Wscript.Echo x
>> Next
>> =========
>> This will produce a different sequence each time it is run. If you want
>> to generate the same sequence each time, seed the generator with a
>> specified value. For example:
>>
>> Randomize(.5)
>>
>> will result in the same sequence each time.
>>
>> No computer generated sequence is truely random, but the Rnd function is
>> better than most. It is based on a maximal length 24-bit linear
>> congruential generator, which is about as good as you can do in VBScript
>> without going to great lengths to avoid overflow errors.
>>
>> --
>> Richard
>> Microsoft MVP Scripting and ADSI
>> Hilltop Lab - http://www.rlmueller.net
>>
>
>



Re: RND not random by Marco

Marco
Fri Dec 08 13:06:06 CST 2006

Thank you,

that works great,

Marco J.L.

"Richard Mueller" <rlmueller-NOSPAM@ameritech.NOSPAM.net> wrote in message
news:%233OuIKvGHHA.3952@TK2MSFTNGP02.phx.gbl...
> If you are using the Randomize function (with no parameters) and still
> getting the same sequence each time, that is strange. I cannot duplicate
> that. I'd like to know what OS your script is running under.
>
> I've studied the Rnd function and actually figured out the Linear
> Congruential Generator used. I could give you the code for this, or a
> similar generator, but you would have the same problem, how to seed it
> with a random value that will result in a different sequence each time it
> is run. I studied the Randomize function, but was never able to figure it
> out. It is supposed to seed Rnd with a value from the system clock. While
> Rnd only outputs numbers between 0 and 1, you can pass any value to
> Randomize. One solution for you would be to use the output from the Timer
> function, which is the number of seconds since midnight (to the nearests
> 100th of a second). For example:
> ================
> y = Timer
> Randomize y
> For k = 1 To 10
> x = Int(Rnd * 1000000)
> Wscript.Echo x
> Next
> ================
> If you are worried about the chance of generating the same sequence at the
> same time each day, you could add in the current date. The Date function
> returns the number of days since 12/30/1899. Perhaps:
> ==========
> y = Timer
> z = Date
> Randomize y + z
> ==========
> Or, you could somehow retain a sequential number to seed the generator,
> incrementing it each time the script runs. The way psuedo random number
> generators work, you will still get completely different sequences. For
> example, to demonstrate:
> ============
> For j = 101 To 105
> ' The next number in the sequence seeds the generator each day.
> Randomize j
> For k = 1 To 10
> x = Int(Rnd * 1000000)
> Wscript.Echo j & ": " & x
> Next
> Next
>
> --
> Richard
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
>
> "Marco J.L." <luyenews@yahoo.com.news> wrote in message
> news:u3KkrsuGHHA.1784@TK2MSFTNGP06.phx.gbl...
>> Why do I always get the same output when I run the script again?
>>
>>
>>
>>
>> "Richard Mueller" <rlmueller-NOSPAM@ameritech.NOSPAM.net> wrote in
>> message news:%233gG$WuGHHA.4920@TK2MSFTNGP05.phx.gbl...
>>> Marco J.L. wrote:
>>>
>>>> rnd() is not random (on my computer)
>>>>
>>>> Does anyone has an option for generating random numbers? I need random
>>>> numbers between 0 and a million (1000000)
>>>
>>> Did you initialize the seed for the psuedo random number generator with
>>> the Randomize command? This seeds the generator with a value from the
>>> system clock. For example:
>>> =========
>>> Randomize
>>> For k = 1 To 10
>>> x = Int(Rnd * 1000000)
>>> Wscript.Echo x
>>> Next
>>> =========
>>> This will produce a different sequence each time it is run. If you want
>>> to generate the same sequence each time, seed the generator with a
>>> specified value. For example:
>>>
>>> Randomize(.5)
>>>
>>> will result in the same sequence each time.
>>>
>>> No computer generated sequence is truely random, but the Rnd function is
>>> better than most. It is based on a maximal length 24-bit linear
>>> congruential generator, which is about as good as you can do in VBScript
>>> without going to great lengths to avoid overflow errors.
>>>
>>> --
>>> Richard
>>> Microsoft MVP Scripting and ADSI
>>> Hilltop Lab - http://www.rlmueller.net
>>>
>>
>>
>
>



Re: RND not random by Dr

Dr
Fri Dec 08 17:37:28 CST 2006

In microsoft.public.scripting.vbscript message
<#3gG$WuGHHA.4920@TK2MSFTNGP05.phx.gbl>, Fri, 8 Dec 2006 10:27:23,
Richard Mueller <rlmueller-NOSPAM@ameritech.NOSPAM.net> wrote:
>
>No computer generated sequence is truely random, but the Rnd function is
>better than most. It is based on a maximal length 24-bit linear congruential
>generator, which is about as good as you can do in VBScript without going to
>great lengths to avoid overflow errors.


AIUI, in both VBScript and Javascript the output of the "random" routine
is an IEEE Double X with 0 <= X < 1 (bugs apart).

There is no need for the routine itself to be written in the
corresponding script language; it should be written in whatever
language(s) the script support routines are written in, maybe C++ or
ASM.

In Jscript, in IE4 & IE6, my tests show a 53-bit resolution for the
result; that's the resolution of an IEEE Double. So the internal
generator resolution is *at least* 53 bits. See in "Generator
Properties" under <URL:http://www.merlyn.demon.co.uk/js-randm.htm#MR>

I see no good reason why VBS rnd should not be as good; if it is not,
that's an implementation weakness.

Fx : checks page : <URL:http://www.merlyn.demon.co.uk/vb-maths.htm#Rand>
shows, IMHO, in IE4 & IE6, that it is indeed a 24-bit generator. Sigh.


In another article:

>returns the number of days since 12/30/1899.

This newsgroup has world-wide circulation. Therefore, please do not use
quaint local formats where there is a perfectly good, unambiguous,
logical, international standard for numeric dates.
--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk DOS 3.3, 6.20; WinXP.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL:http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <URL:http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.

Re: RND not random by Richard

Richard
Mon Dec 11 14:45:44 CST 2006

As John Stockton notes, VBScript stores numbers internally accurate to 53
bits. VBScript never displays more than 15 digits (the number is padded with
zeros if you request more), but internally the precision to 53 bits is
maintained. The pseudo random number generator behind the VBScript Rnd
function is a linear congruential generator of the form:




Xi+1 = (A * Xi + C) Mod M




where A, C, and M are constants. M is 2^24 (16,777,216), which is why we
call the generator 24-bit. If A and C are chosen carefully (which they are),
the generator will be maximal length with a period of 2^24. The generator
produces integers from 0 to 2^24-1. The Rnd function takes the integer,
divides by the modulus (2^24), and displays the 7 most significant digits
(greater than or equal to 0 and less than 1).




I think Microsoft felt it would be too much trouble to code a better
generator. All calculations must be exact, with no round off error. The
product (A * Xi) in the 24-bit generator requires 48 bits to be represented
exactly. The VBScript Mod function overflows at 2^31, but the number can be
calculated by dividing by M and taking the remainder. The result is exact.




A generator with a larger modulus could be coded in a different language,
like assembly. A VBScript program would require two variables to store all
values (a high part and low part). The product (A * Xi) could be calculated
exactly and we could add C. The problem would be coding the Mod function of
a number larger than 2^53. Using long division would be a pain.




A better solution would be to use a generator with a modulus that is a power
of 10 rather than 2. Then we don't have to do the long division. Instead,
because the numbers are base 10, we can just discard the high part of the
result (as can be done easily in assembly language with a modulus that is a
power of 2). For example, below is a linear congruential generator with
modulus 10^14 (which is better than 46 bits) and period 10^14. This program
displays integers, but you could easily normalize by dividing by the modulus
10^14.

==============

Option Explicit



Dim lngValue, k



' Constants for Linear Conguential Generator.
Const A_Hi = 8986055
Const A_Lo = 3222621
Const C_Hi = 4611540
Const C_Lo = 9781439
' Modulus is 10^14.
Const M = 100000000000000
' Constant for breaking numbers into High and Low parts.
Const H = 10000000



' Argument is the initial seed value.

' This should be greater or equal to 0 and less than 10^14.
lngValue = Wscript.Arguments(0)
Wscript.Echo FormatNumber(lngValue, 0)



' Display the next 10 integers produced
' by the linear congruential generator.
For k = 1 To 10
lngValue = LCG(lngValue)
Wscript.Echo FormatNumber(lngValue, 0)
Next



Function LCG(ByRef lngSeed)
' Psuedo Random Number Generator based on
' the Linear Congruential Generator
' LCG = (A * lngSeed + C) Mod M
' where the values are broken into high and low parts as follows
' A = A_Hi * 10^7 + A_Lo
' C = C_Hi * 10^7 + C_Lo
' lngSeed = S_Hi * 10^7 + S_Lo
' lngSeed is an integer greater than or equal to 0
' and less than M. Function returns an integer greater
' than or equal to 0 and less than M.



Dim L1, L2, L3, S_Hi, S_Lo



' Break up seed value into high and low parts.
S_Hi = Fix(lngSeed / H)
S_Lo = lngSeed - (S_Hi * H)



' Calculate intermediate results.
' The term (A_Hi * S_Hi) is discarded by the Mod function.
L2 = (A_Hi * S_Lo) + (A_Lo * S_Hi)
L3 = A_Lo * S_Lo



' We only need the low part of L2, the upper part is discarded
' by the Mod function.
L1 = Fix(L2 / H)
L2 = L2 - (L1 * H)

LCG = ((L2 + C_Hi) * (10^7)) + L3 + C_Lo



' Again, we can discard the high part of the final result.
L1 = Fix(LCG / M)
LCG = LCG - (L1 * M)

End Function
=============

Per Donald Knuth in "The Art of Computer Programming, Volume 2,
Seminumerical Algorithms", this generator is maximal length because:



C is relatively prime to M
B = A - 1 is a multiple of P, for every prime P dividing M
B is a multiple of 4, if M is a multiple of 4


In this case, M is a multiple of 4. The prime factors of M are 2 and 5.

A = 89,860,553,222,621

C = 46,115,409,781,439



A = 6,037 * 10,531 * 1,413,443

C is prime



B = 89,860,553,222,620 is a multiple of both 2 and 5, and also of 4

B = 2 * 2 * 5 * 4,493,027,661,131



Also:



A Mod 200 = 21

A is about 0.9 * M
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net



Re: RND not random by Bob

Bob
Mon Dec 11 16:29:21 CST 2006

Richard Mueller wrote:
> I think Microsoft felt it would be too much trouble to code a better
> generator. All calculations must be exact, with no round off error. The
> product (A * Xi) in the 24-bit generator requires 48 bits to be represented
> exactly. The VBScript Mod function overflows at 2^31, but the number can be
> calculated by dividing by M and taking the remainder. The result is exact.

Why?
When M is a power of two, a simple AND operation will suffice.

Performance-wise, it's unlikely any alternative implementation
could even come close.



Bob
--

Re: RND not random by Bob

Bob
Mon Dec 11 16:56:45 CST 2006

For in-depth discussions of random numbers go to the
sci.crypt.random-numbers newsgroup.

RND not being random is common across a number of programming languages. It
allows for repeatable results when using the same seed

Bob

"Bob O`Bob" <filterbob@yahoogroups.com> wrote in message
news:OUQDQPXHHHA.3540@TK2MSFTNGP02.phx.gbl...
> Richard Mueller wrote:
>> I think Microsoft felt it would be too much trouble to code a better
>> generator. All calculations must be exact, with no round off error. The
>> product (A * Xi) in the 24-bit generator requires 48 bits to be
>> represented exactly. The VBScript Mod function overflows at 2^31, but the
>> number can be calculated by dividing by M and taking the remainder. The
>> result is exact.
>
> Why?
> When M is a power of two, a simple AND operation will suffice.
>
> Performance-wise, it's unlikely any alternative implementation
> could even come close.
>
>
>
> Bob
> --



Re: RND not random by Richard

Richard
Mon Dec 11 17:36:38 CST 2006


"Bob O`Bob" <filterbob@yahoogroups.com> wrote in message
news:OUQDQPXHHHA.3540@TK2MSFTNGP02.phx.gbl...
> Richard Mueller wrote:
>> I think Microsoft felt it would be too much trouble to code a better
>> generator. All calculations must be exact, with no round off error. The
>> product (A * Xi) in the 24-bit generator requires 48 bits to be
>> represented exactly. The VBScript Mod function overflows at 2^31, but the
>> number can be calculated by dividing by M and taking the remainder. The
>> result is exact.
>
> Why?
> When M is a power of two, a simple AND operation will suffice.
>
> Performance-wise, it's unlikely any alternative implementation
> could even come close.

I'll be the first to admit I don't completely understand the AND, XOR, and
OR operators. However I can't duplicate the Mod function with these. For
example:

Const M = 8
lngValue = 43
Wscript.Echo lngValue AND M
Wscript.Echo lngValue OR M
Wscript.Echo lngValue XOR M
Wscript.Echo lngValue Mod M

Only the last results in the correct value of 3. Am I missing something?

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net



Re: RND not random by Bob

Bob
Mon Dec 11 19:15:10 CST 2006

Richard Mueller wrote:
> "Bob O`Bob" <filterbob@yahoogroups.com> wrote in message
> news:OUQDQPXHHHA.3540@TK2MSFTNGP02.phx.gbl...
>> Richard Mueller wrote:
>>> I think Microsoft felt it would be too much trouble to code a better
>>> generator. All calculations must be exact, with no round off error. The
>>> product (A * Xi) in the 24-bit generator requires 48 bits to be
>>> represented exactly. The VBScript Mod function overflows at 2^31, but the
>>> number can be calculated by dividing by M and taking the remainder. The
>>> result is exact.
>> Why?
>> When M is a power of two, a simple AND operation will suffice.
>>
>> Performance-wise, it's unlikely any alternative implementation
>> could even come close.
>
> I'll be the first to admit I don't completely understand the AND, XOR, and
> OR operators. However I can't duplicate the Mod function with these. For
> example:
>
> Const M = 8
> lngValue = 43
> Wscript.Echo lngValue AND M
> Wscript.Echo lngValue OR M
> Wscript.Echo lngValue XOR M
> Wscript.Echo lngValue Mod M
>
> Only the last results in the correct value of 3. Am I missing something?
>

... And (M - 1)

Re: RND not random by Richard

Richard
Mon Dec 11 23:57:00 CST 2006


"Bob O`Bob" <filterbob@yahoogroups.com> wrote in message
news:OFbY6rYHHHA.960@TK2MSFTNGP04.phx.gbl...
> Richard Mueller wrote:
>> "Bob O`Bob" <filterbob@yahoogroups.com> wrote in message
>> news:OUQDQPXHHHA.3540@TK2MSFTNGP02.phx.gbl...
>>> Richard Mueller wrote:
>>>> I think Microsoft felt it would be too much trouble to code a better
>>>> generator. All calculations must be exact, with no round off error. The
>>>> product (A * Xi) in the 24-bit generator requires 48 bits to be
>>>> represented exactly. The VBScript Mod function overflows at 2^31, but
>>>> the number can be calculated by dividing by M and taking the remainder.
>>>> The result is exact.
>>> Why?
>>> When M is a power of two, a simple AND operation will suffice.
>>>
>>> Performance-wise, it's unlikely any alternative implementation
>>> could even come close.
>>
>> I'll be the first to admit I don't completely understand the AND, XOR,
>> and OR operators. However I can't duplicate the Mod function with these.
>> For example:
>>
>> Const M = 8
>> lngValue = 43
>> Wscript.Echo lngValue AND M
>> Wscript.Echo lngValue OR M
>> Wscript.Echo lngValue XOR M
>> Wscript.Echo lngValue Mod M
>>
>> Only the last results in the correct value of 3. Am I missing something?
>>
>
> ... And (M - 1)

I didn't know that. Next problem is that the AND operator overflows (in
VBScript) if either number is greater than 2^31 - 1. If M is 2^31, for
example, lngValue could be a prime number much larger than 2^31. I see no
workaround.

Richard



Re: RND not random by Bob

Bob
Tue Dec 12 00:57:57 CST 2006

Richard Mueller wrote:

>>> I'll be the first to admit I don't completely understand the AND, XOR,
>>> and OR operators. However I can't duplicate the Mod function with these.
>>> For example:
>>>
>>> Const M = 8
>>> lngValue = 43
>>> Wscript.Echo lngValue AND M
>>> Wscript.Echo lngValue OR M
>>> Wscript.Echo lngValue XOR M
>>> Wscript.Echo lngValue Mod M
>>>
>>> Only the last results in the correct value of 3. Am I missing something?
>>>
>> ... And (M - 1)
>
> I didn't know that. Next problem is that the AND operator overflows (in
> VBScript) if either number is greater than 2^31 - 1. If M is 2^31, for
> example, lngValue could be a prime number much larger than 2^31. I see no
> workaround.


I don't understand what you're describing.
It's conceptually impossible for any And operator to "overflow"
I think you may be mistaking an overflow occurring in some other operation
in a complex statement.

I'm much more familiar with VB, but I believe variants of vartype Long are
probably the same as in VBScript, and those do overflow at that point, and
properly so - because there is no unsigned version. If you want to use that
highest bit, work-arounds are necessary.

My VBS references do indicate that the currency subtype is available,
and that should give considerably more range. With care, it can be used
for a full 64 bits of (signed) math operations, though I think the bitwise
operators (And, Or, Xor) remain limited to the range of a Long. There are
ways to work around that, too, in "Full" VB, where we can LSet the bytes of
a Currency variable into a composite type of smaller variables such as a
byte array. It probably could be done even in script with some portioning
functions like you've done in base-10, but IMO perhaps more simply.



Bob
--

Re: RND not random by Dr

Dr
Tue Dec 12 07:26:25 CST 2006

In microsoft.public.scripting.vbscript message
<#QTglVWHHHA.3616@TK2MSFTNGP02.phx.gbl>, Mon, 11 Dec 2006 14:45:44,
Richard Mueller <rlmueller-NOSPAM@ameritech.NOSPAM.net> wrote:

>I think Microsoft felt it would be too much trouble to code a better
>generator. All calculations must be exact, with no round off error. The
>product (A * Xi) in the 24-bit generator requires 48 bits to be represented
>exactly. The VBScript Mod function overflows at 2^31, but the number can be
>calculated by dividing by M and taking the remainder. The result is exact.

But they did it for JScript, where the underlying routine is at least
53-bit; and they could have seen how it was done by Borland (Pascal has
a 32-bit generator for a 16-bit instruction set). For those who know
Assembler and the basic instruction set (and Microsoft should have staff
who do), the task is easy.

The primitive functions of a higher-level language should only be coded
in the language itself if the resulting code executed is at least almost
as good as it could be if it were written in Assembler.

It's a good idea to read news:comp.lang.javascript and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
<URL:http://www.jibbering.com/faq/> Old 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.

Re: RND not random by Richard

Richard
Tue Dec 12 15:07:22 CST 2006

"Dr J R Stockton" <reply0650@merlyn.demon.co.uk> wrote in message
news:dTPxtmUB4qfFFw08@invalid.uk.co.demon.merlyn.invalid...
> In microsoft.public.scripting.vbscript message
> <#QTglVWHHHA.3616@TK2MSFTNGP02.phx.gbl>, Mon, 11 Dec 2006 14:45:44,
> Richard Mueller <rlmueller-NOSPAM@ameritech.NOSPAM.net> wrote:
>
>>I think Microsoft felt it would be too much trouble to code a better
>>generator. All calculations must be exact, with no round off error. The
>>product (A * Xi) in the 24-bit generator requires 48 bits to be
>>represented
>>exactly. The VBScript Mod function overflows at 2^31, but the number can
>>be
>>calculated by dividing by M and taking the remainder. The result is exact.
>
> But they did it for JScript, where the underlying routine is at least
> 53-bit; and they could have seen how it was done by Borland (Pascal has a
> 32-bit generator for a 16-bit instruction set). For those who know
> Assembler and the basic instruction set (and Microsoft should have staff
> who do), the task is easy.
>
> The primitive functions of a higher-level language should only be coded in
> the language itself if the resulting code executed is at least almost as
> good as it could be if it were written in Assembler.
>
> It's a good idea to read news:comp.lang.javascript and its FAQ. See below.
>

I agree. A 64-bit generator is fairly easy to code in assembly. Years ago I
coded a generator in assembly that combined a 64-bit linear congruential
generator, a multiply with carry generator, and an extended linear
congruential generator. I believe the period of the combined generator is
about 2^222.

Even if VB could calculate the mod of a 64-bit number using the currency
datatype (which I believe would be difficult), this would only allow you to
code a 32-bit linear congruential generator.

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net



Re: RND not random by Bob

Bob
Tue Dec 12 16:22:03 CST 2006

Richard Mueller wrote:
> "Dr J R Stockton" <reply0650@merlyn.demon.co.uk> wrote in message
> news:dTPxtmUB4qfFFw08@invalid.uk.co.demon.merlyn.invalid...
>> In microsoft.public.scripting.vbscript message
>> <#QTglVWHHHA.3616@TK2MSFTNGP02.phx.gbl>, Mon, 11 Dec 2006 14:45:44,
>> Richard Mueller <rlmueller-NOSPAM@ameritech.NOSPAM.net> wrote:
>>
>>> I think Microsoft felt it would be too much trouble to code a better
>>> generator. All calculations must be exact, with no round off error. The
>>> product (A * Xi) in the 24-bit generator requires 48 bits to be
>>> represented
>>> exactly. The VBScript Mod function overflows at 2^31, but the number can
>>> be
>>> calculated by dividing by M and taking the remainder. The result is exact.
>> But they did it for JScript, where the underlying routine is at least
>> 53-bit; and they could have seen how it was done by Borland (Pascal has a
>> 32-bit generator for a 16-bit instruction set). For those who know
>> Assembler and the basic instruction set (and Microsoft should have staff
>> who do), the task is easy.
>>
>> The primitive functions of a higher-level language should only be coded in
>> the language itself if the resulting code executed is at least almost as
>> good as it could be if it were written in Assembler.
>>
>> It's a good idea to read news:comp.lang.javascript and its FAQ. See below.
>>
>
> I agree. A 64-bit generator is fairly easy to code in assembly. Years ago I
> coded a generator in assembly that combined a 64-bit linear congruential
> generator, a multiply with carry generator, and an extended linear
> congruential generator. I believe the period of the combined generator is
> about 2^222.
>
> Even if VB could calculate the mod of a 64-bit number using the currency
> datatype (which I believe would be difficult), this would only allow you to
> code a 32-bit linear congruential generator.
>


But math of /arbitrary/ precision could be done using byte arrays.

Oh, and /a/ way to calculate MOD in a Currency type would be to do the
division, multiplication, and subtraction. One might have to include
an addition to check for roundoff, and perhaps have a slightly different
version of the algorithm for when the sign bit is high. But I have no
doubt I could do it, given a little time and motivation.

Nor do I know how well it would translate into script.


Bob
--

Re: RND not random by asdf

asdf
Thu Dec 14 03:21:13 CST 2006

Randomness can not have a determining stimulant.


----------------------------------------------------------------------------
----------

Unless you want to redo your phd, I sugesst you to
be more realistic.

***********************

We are not stupid.

========

All your Premier could come up with was a copied paper.




-------------

I think you are while honest overrating your own knowledge.


None of your "reasoning links" for thrird party analisys can not be found
but lots of your won gagging along "all times are london".




"Dr J R Stockton" <reply0650@merlyn.demon.co.uk> wrote in message
news:dTPxtmUB4qfFFw08@invalid.uk.co.demon.merlyn.invalid...
> In microsoft.public.scripting.vbscript message
> <#QTglVWHHHA.3616@TK2MSFTNGP02.phx.gbl>, Mon, 11 Dec 2006 14:45:44,
> Richard Mueller <rlmueller-NOSPAM@ameritech.NOSPAM.net> wrote:
>
> >I think Microsoft felt it would be too much trouble to code a better
> >generator. All calculations must be exact, with no round off error. The
> >product (A * Xi) in the 24-bit generator requires 48 bits to be
represented
> >exactly. The VBScript Mod function overflows at 2^31, but the number can
be
> >calculated by dividing by M and taking the remainder. The result is
exact.
>
> But they did it for JScript, where the underlying routine is at least
> 53-bit; and they could have seen how it was done by Borland (Pascal has
> a 32-bit generator for a 16-bit instruction set). For those who know
> Assembler and the basic instruction set (and Microsoft should have staff
> who do), the task is easy.
>
> The primitive functions of a higher-level language should only be coded
> in the language itself if the resulting code executed is at least almost
> as good as it could be if it were written in Assembler.
>
> It's a good idea to read news:comp.lang.javascript and its FAQ. See below.
>
> --
> (c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05
IE 6
> <URL:http://www.jibbering.com/faq/> Old 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.


Re: RND not random by asdf

asdf
Sat Dec 16 06:01:16 CST 2006

This is a multi-part message in MIME format.

------=_NextPart_000_009C_01C720DF.FAD7F000
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Discovered a page of your site with new
lighter coloring, GOOD.

I miss soem straight foreward real live
stuff.

E.g.

Displaying device or disk capacity with
DOTS.

----------------

AKA :


123456789 becomes 123.456.789 bytes


//formatDriveCapacityNotation
function format3(i){
var sNum = String(i)
var aNum =
sNum.match(/\d/ig).reverse()
for(var i = 3 ; i < aNum.length ;
i+=3){
aNum[i-1] = "." + aNum[i-1]
}
return aNum.reverse().join("")
}


--------------------

If came up with lesser knowledge to
regex than you may have.

So your improvements, before I need to
study the category and
subcategory language to the year the
franks invaded britan in 201,
not, I really need it when i need it
then or now - quicker.

and explicitly with a search box.

I hope that does not add to the pale
white and taste of my prior posts to
your publication references.



"asdf" <asdf@asdf.com> wrote in message
news:urG%232E2HHHA.4760@TK2MSFTNGP03.phx.gbl...
> Randomness can not have a determining
stimulant.
>
>
> --------------------------------------
--------------------------------------
> ----------
>
> Unless you want to redo your phd, I
sugesst you to
> be more realistic.
>
> ***********************
>
> We are not stupid.
>
> ========
>
> All your Premier could come up with
was a copied paper.
>
>
>
>
> -------------
>
> I think you are while honest
overrating your own knowledge.
>
>
> None of your "reasoning links" for
thrird party analisys can not be found
> but lots of your won gagging along
"all times are london".
>
>
>
>
> "Dr J R Stockton"
<reply0650@merlyn.demon.co.uk> wrote in
message
>
news:dTPxtmUB4qfFFw08@invalid.uk.co.demon.merlyn.invalid...
> > In
microsoft.public.scripting.vbscript
message
> >
<#QTglVWHHHA.3616@TK2MSFTNGP02.phx.gbl>,
Mon, 11 Dec 2006 14:45:44,
> > Richard Mueller
<rlmueller-NOSPAM@ameritech.NOSPAM.net>
wrote:
> >
> > >I think Microsoft felt it would be
too much trouble to code a better
> > >generator. All calculations must be
exact, with no round off error. The
> > >product (A * Xi) in the 24-bit
generator requires 48 bits to be
> represented
> > >exactly. The VBScript Mod function
overflows at 2^31, but the number can
> be
> > >calculated by dividing by M and
taking the remainder. The result is
> exact.
> >
> > But they did it for JScript, where
the underlying routine is at least
> > 53-bit; and they could have seen how
it was done by Borland (Pascal has
> > a 32-bit generator for a 16-bit
instruction set). For those who know
> > Assembler and the basic instruction
set (and Microsoft should have staff
> > who do), the task is easy.
> >
> > The primitive functions of a
higher-level language should only be
coded
> > in the language itself if the
resulting code executed is at least
almost
> > as good as it could be if it were
written in Assembler.
> >
> > It's a good idea to read
news:comp.lang.javascript and its FAQ.
See below.
> >
> > --
> > (c) John Stockton, Surrey, UK.
?@merlyn.demon.co.uk Turnpike v6.05
> IE 6
> >
<URL:http://www.jibbering.com/faq/> Old
RC FAQ of
> news:comp.lang.javascript
> >
<URL:http://www.merlyn.demon.co.uk/js-in
dex.htm> jscr maths, dates,
> sources.
> >
<URL:http://www.merlyn.demon.co.uk/>
TP/BP/Delphi/jscr/&c, FAQ items,
> links.
>

------=_NextPart_000_009C_01C720DF.FAD7F000
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1555" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT size=3D2>Discovered a page of your site with new lighter =
coloring,=20
GOOD.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>I miss soem straight foreward real live =
stuff.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>E.g.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Displaying device or disk capacity with =
DOTS.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>----------------</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>AKA : </FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>123456789 becomes </FONT><FONT size=3D2>123.456.789=20
bytes</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New"=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//formatDriveCapacityNotation<BR>&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function=20
format3(i){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var sNum =3D=20
String(i)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var aNum =3D=20
sNum.match(/\d/ig).reverse()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(v=
ar i =3D=20
3 ; i &lt; aNum.length ;=20
i+=3D3){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aNum[i-1] =3D "." =
+=20
aNum[i-1]<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;return=20
aNum.reverse().join("")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>--------------------</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>If came up with lesser knowledge to regex than you =
may=20
have.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>So your improvements, before I need to study the =
category and=20
</FONT></DIV>
<DIV><FONT size=3D2>subcategory language to the year the franks invaded =
britan in=20
201,</FONT></DIV>
<DIV><FONT size=3D2>not, &nbsp;I really need it when i need it then or =
now -=20
quicker.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>and explicitly with a search box.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>I hope that does not add to the pale white and taste =
of my=20
prior posts to your publication references.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>"asdf" &lt;</FONT><A =
href=3D"mailto:asdf@asdf.com"><FONT=20
size=3D2>asdf@asdf.com</FONT></A><FONT size=3D2>&gt; wrote in message =
</FONT><A=20
href=3D"news:urG%232E2HHHA.4760@TK2MSFTNGP03.phx.gbl"><FONT=20
size=3D2>news:urG%232E2HHHA.4760@TK2MSFTNGP03.phx.gbl</FONT></A><FONT=20
size=3D2>...</FONT></DIV><FONT size=3D2>&gt; Randomness can not have a =
determining=20
stimulant.<BR>&gt; <BR>&gt; <BR>&gt;=20
-------------------------------------------------------------------------=
---<BR>&gt;=20
----------<BR>&gt; <BR>&gt; Unless you want to redo your phd, I sugesst =
you=20
to<BR>&gt; be more realistic.<BR>&gt; <BR>&gt; =
***********************<BR>&gt;=20
<BR>&gt; We are not stupid.<BR>&gt; <BR>&gt; =
=3D=3D=3D=3D=3D=3D=3D=3D<BR>&gt; <BR>&gt; All your=20
Premier could come up with was a copied paper.<BR>&gt; <BR>&gt; <BR>&gt; =

<BR>&gt; <BR>&gt; -------------<BR>&gt; <BR>&gt; I think you are while =
honest=20
overrating your own knowledge.<BR>&gt; <BR>&gt; <BR>&gt; None of your =
"reasoning=20
links" for thrird party analisys can not be found<BR>&gt; but lots of =
your won=20
gagging along "all times are london".<BR>&gt; <BR>&gt; <BR>&gt; <BR>&gt; =

<BR>&gt; "Dr J R Stockton" &lt;</FONT><A=20
href=3D"mailto:reply0650@merlyn.demon.co.uk"><FONT=20
size=3D2>reply0650@merlyn.demon.co.uk</FONT></A><FONT size=3D2>&gt; =
wrote in=20
message<BR>&gt; </FONT><A=20
href=3D"news:dTPxtmUB4qfFFw08@invalid.uk.co.demon.merlyn.invalid"><FONT=20
size=3D2>news:dTPxtmUB4qfFFw08@invalid.uk.co.demon.merlyn.invalid</FONT><=
/A><FONT=20
size=3D2>...<BR>&gt; &gt; In microsoft.public.scripting.vbscript =
message<BR>&gt;=20
&gt; &lt;</FONT><A =
href=3D"mailto:#QTglVWHHHA.3616@TK2MSFTNGP02.phx.gbl"><FONT=20
size=3D2>#QTglVWHHHA.3616@TK2MSFTNGP02.phx.gbl</FONT></A><FONT =
size=3D2>&gt;, Mon,=20
11 Dec 2006 14:45:44,<BR>&gt; &gt; Richard Mueller &lt;</FONT><A=20
href=3D"mailto:rlmueller-NOSPAM@ameritech.NOSPAM.net"><FONT=20
size=3D2>rlmueller-NOSPAM@ameritech.NOSPAM.net</FONT></A><FONT =
size=3D2>&gt;=20
wrote:<BR>&gt; &gt;<BR>&gt; &gt; &gt;I think Microsoft felt it would be =
too much=20
trouble to code a better<BR>&gt; &gt; &gt;generator. All calculations =
must be=20
exact, with no round off error. The<BR>&gt; &gt; &gt;product (A * Xi) in =
the=20
24-bit generator requires 48 bits to be<BR>&gt; represented<BR>&gt; &gt; =

&gt;exactly. The VBScript Mod function overflows at 2^31, but the number =

can<BR>&gt; be<BR>&gt; &gt; &gt;calculated by dividing by M and taking =
the=20
remainder. The result is<BR>&gt; exact.<BR>&gt; &gt;<BR>&gt; &gt; But =
they did=20
it for JScript, where the underlying routine is at least<BR>&gt; &gt; =
53-bit;=20
and they could have seen how it was done by Borland (Pascal has<BR>&gt; =
&gt; a=20
32-bit generator for a 16-bit instruction set).&nbsp; For those who =
know<BR>&gt;=20
&gt; Assembler and the basic instruction set (and Microsoft should have=20
staff<BR>&gt; &gt; who do), the task is easy.<BR>&gt; &gt;<BR>&gt; &gt; =
The=20
primitive functions of a higher-level language should only be =
coded<BR>&gt; &gt;=20
in the language itself if the resulting code executed is at least =
almost<BR>&gt;=20
&gt; as good as it could be if it were written in Assembler.<BR>&gt;=20
&gt;<BR>&gt; &gt; It's a good idea to read </FONT><A=20
href=3D"news:comp.lang.javascript"><FONT=20
size=3D2>news:comp.lang.javascript</FONT></A><FONT size=3D2> and its =
FAQ. See=20
below.<BR>&gt; &gt;<BR>&gt; &gt; -- <BR>&gt; &gt;&nbsp;&nbsp; (c) John =
Stockton,=20
Surrey, UK.&nbsp; </FONT><A href=3D"mailto:?@merlyn.demon.co.uk"><FONT=20
size=3D2>?@merlyn.demon.co.uk</FONT></A><FONT size=3D2>&nbsp;&nbsp; =
Turnpike=20
v6.05<BR>&gt; IE 6<BR>&gt; &gt;&nbsp;&nbsp; &lt;</FONT><A=20
href=3D"http://www.jibbering.com/faq/"><FONT=20
size=3D2>URL:http://www.jibbering.com/faq/</FONT></A><FONT =
size=3D2>&gt;&nbsp; Old=20
RC FAQ of<BR>&gt; </FONT><A href=3D"news:comp.lang.javascript"><FONT=20
size=3D2>news:comp.lang.javascript</FONT></A><BR><FONT size=3D2>&gt;=20
&gt;&nbsp;&nbsp; &lt;</FONT><A=20
href=3D"http://www.merlyn.demon.co.uk/js-index.htm"><FONT=20
size=3D2>URL:http://www.merlyn.demon.co.uk/js-index.htm</FONT></A><FONT=20
size=3D2>&gt; jscr maths, dates,<BR>&gt; sources.<BR>&gt; =
&gt;&nbsp;&nbsp;=20
&lt;</FONT><A href=3D"http://www.merlyn.demon.co.uk/"><FONT=20
size=3D2>URL:http://www.merlyn.demon.co.uk/</FONT></A><FONT =
size=3D2>&gt;=20
TP/BP/Delphi/jscr/&amp;c, FAQ items,<BR>&gt; links.<BR>&gt;=20
</FONT></BODY></HTML>

------=_NextPart_000_009C_01C720DF.FAD7F000--