Page 1 of 1

Random numbers.

Posted: Sun Nov 07, 2010 12:29 pm
by bokkie
Chaps, given this sample code that uses the Mathematics plugin...

Set Variable I to
Set Random Number Generator Seed = 123456789
I = Generate Random Number (max value 8888)
MessageBox: , $I$
I = Generate Random Number (max value 4000)
MessageBox: , $I$

I always get back 0 for the random number values. I've tried lots of different variations but I'm missing something. Can anyone tell me what I'm doing wrong?

Edit: I found that using this statement Set Random Number Generator Constants = 3848484757, 23945987987987 before generating numbers had an effect but I can't find anything that describes what it actually does and what the significance of the two parameters is. What do those parameters do?

Re: Random numbers.

Posted: Mon Nov 08, 2010 2:48 pm
by mills
The help doc hasn't been updated for this, yet. Here's the behavior I've documented:

Set Random Number Generator Constants. Operand 1 sets Constant1 and Operand 2 sets Constant2.

Set Random Number Generator Seed - Accepts Operand 1 as the seed. Operand 2 is ignored.

Generate Random Number - Generates a random number. Use Operand 1 (required) to define a maximum return value and Operand 2 (optional) to define a minimum return value. Default minimum value is 0. The result of this operation is equal to: Seed x Constant1 + Constant2.

Re: Random numbers.

Posted: Wed Nov 10, 2010 11:02 am
by bokkie
Andy,

I've had a few minutes to try some things. Could you create a blank setup project and copy this code into it:

~InstallAware Clipboard Data~
~Comment~
~{E9AD2A82-CD58-4209-8370-37B5A13CB244}~
~~
~MessageBox~
~{C7BF3DD6-DC55-4D10-91B2-91577C82C635}~
~~
~$X$~
~0~
~1~
~~
~Mathematics~
~{079AC257-5E7F-47C3-84F0-BE09C7877319}~
~3~
~2~
~15~
~X~
~Set Variable~
~{FC2A19B3-CA21-42AF-A5E1-A9DC5DDF81CF}~
~I$MYAH$MYAH$FALSE~
~~
~MessageBox~
~{6CEB4746-A30A-40E5-BC03-D50F8B31A1D0}~
~~
~$X$~
~0~
~1~
~~
~Mathematics~
~{2123A01A-2FA8-4B33-A046-AB32BF9039B7}~
~6~
~3~
~13~
~X~
~MessageBox~
~{2B107184-C727-459E-83A1-1361A014603D}~
~~
~$X$~
~0~
~1~
~~
~Mathematics~
~{D7D70167-824A-4619-829B-CB91CABAE3DF}~
~4~
~~
~14~
~X~
~Set Variable~
~{E5555027-714E-4937-9E28-DC68AA8E686A}~
~X$MYAH$MYAH$FALSE~
~~

Now, when I run it, the number I get back is 0 even though I set the maximum value = 3 and the minimum value = 2. I only get back a value 2 or 3 if I set the seed and/or constant numbers to much larger values. That's the bit I can't understand or work out. Any chance you could try this for me and see what you get?

Re: Random numbers.

Posted: Wed Nov 10, 2010 6:14 pm
by mills
I was a little confused on how this all was working myself, particularly after a customer wanted to know how the constants factor into things.

I'm not sure if the Generate Random Number command is supposed to actually generate a random number. I think I'll question this. Like I noted, it's always producing: Seed x Constant1 + Constant2.

Since your max value (3) is less than the output of the formula (27), you get a result of zero. However, it seems like 2 or 3 should be produced.

If you take a look at the serial generation sample, the "randomness" seems to be based more on a string that is fed, to fill all those values than there is any real randomness. I was wondering how it would be able to verify a valid serial number if it's using a random number to compare against the supplied value. It turns out it's not quite as random as one might expect.

Here's the project I used to figure this all out:
Comment: stores the result of operations:
Set Variable result to

Comment: roughly the largest possible value:
Set Variable max to 9223000000000000000

Comment: Minimum value:
Set Variable min to 0

Comment: This will generate 0 each time using default settings
result = Generate Random Number (max value $max$)
Comment: MessageBox: Random, Result = $result$


Comment: This is producing zero each time (regardless of seed value).
Set Random Number Generator Seed = 99954654651
result = Generate Random Number (max value $max$)
Comment: MessageBox: Random, Result = $result$

Comment: Produces zero each time (regardless of seed value)
Set Random Number Generator Seed = 2
Set Random Number Generator Constants = 0, 0
result = Generate Random Number (max value $max$)
MessageBox: Random, Result = $result$

Comment: result = seed with constants 1, 0
Set Random Number Generator Seed = 3
Set Random Number Generator Constants = 1, 0
result = Generate Random Number (max value $max$)
MessageBox: Random, Result = $result$

Comment: This produces a result of 7
Comment: So, it's looking like the formula is:
Comment: Random = Seed * Constant1 + Constant 2
Set Random Number Generator Seed = 3
Set Random Number Generator Constants = 2, 1
result = Generate Random Number (max value $max$)
MessageBox: Random, Result = $result$

Set Random Number Generator Seed = 13
Set Random Number Generator Constants = 23, 69
result = Generate Random Number (max value $max$)
MessageBox: Random, Result = $result$
And the code for your convenience:

Code: Select all

~InstallAware Clipboard Data~
~MessageBox~
~{FD46E878-AD08-4150-8DA4-07D00FC3B986}~
~Random~
~Result = $result$~
~0~
~1~
~~
~Mathematics~
~{C11A4EA6-B867-44D0-8E70-02EE4323F589}~
~$max$~
~~
~15~
~result~
~Mathematics~
~{941DC30E-3E53-4D75-92D3-7458A1B581E1}~
~23~
~69~
~13~
~~
~Mathematics~
~{F4AE5B34-3D66-4E64-8196-457DD486885B}~
~13~
~~
~14~
~result~
~Comment~
~{85D6DD65-2081-478D-9629-E86F9CD953A3}~
~~
~MessageBox~
~{DEAC7658-7599-4807-9E98-1D0772797C37}~
~Random~
~Result = $result$~
~0~
~1~
~~
~Mathematics~
~{790D6D0F-4E72-4F66-B195-1D0C9C917157}~
~$max$~
~~
~15~
~result~
~Mathematics~
~{8D1ED506-2D89-4533-B25C-8CAC4021EDF6}~
~2~
~1~
~13~
~~
~Mathematics~
~{E7748D97-7827-4E18-A221-43BCC3F5D9D4}~
~3~
~~
~14~
~result~
~Comment~
~{5F5A506F-1303-406B-B71B-F0AA2E11ADBD}~
~Random = Seed * Constant1 + Constant 2~
~Comment~
~{12301B4C-9ABB-4B26-BDC1-6FFA70342F8D}~
~So, it's looking like the formula is:~
~Comment~
~{3ECC32BF-4615-4491-BFB9-60A6B4026DCC}~
~This produces a result of 7~
~Comment~
~{9CC6289A-A21E-4D89-BA9B-981B1CF35A32}~
~~
~MessageBox~
~{120E308F-D489-4FC8-ADA2-9CEE4C9D9525}~
~Random~
~Result = $result$~
~0~
~1~
~~
~Mathematics~
~{8A3C7968-3969-4725-A8C3-D3FE88F79A49}~
~$max$~
~~
~15~
~result~
~Mathematics~
~{A4511451-D723-419B-8A9A-1A4C9C2D9974}~
~1~
~0~
~13~
~result~
~Mathematics~
~{4FDBDC2E-1C90-49CF-B957-16F2E03AB128}~
~3~
~~
~14~
~result~
~Comment~
~{A88DFF9C-93E3-4D43-9B44-B16F8087C785}~
~result = seed with constants 1, 0~
~Comment~
~{B81CEEF1-8F5D-465E-BE2E-9E013A6D6C89}~
~~
~MessageBox~
~{18B57DA4-586F-4DF0-925B-6F3F65A2A44A}~
~Random~
~Result = $result$~
~0~
~1~
~~
~Mathematics~
~{4D0C017C-DC8B-471C-B644-4881CAB1D877}~
~$max$~
~~
~15~
~result~
~Mathematics~
~{3B36AEA5-ED1C-4AB9-8A60-1DA8BF7C2E71}~
~0~
~0~
~13~
~result~
~Mathematics~
~{B6212C15-0C4A-499D-B741-6189E56F7F89}~
~2~
~~
~14~
~result~
~Comment~
~{3F1BD02A-BA56-40BF-BCE9-BA1FF9BD3AF3}~
~Produces zero each time (regardless of seed value)~
~Comment~
~{888E17CD-5022-42DE-9570-8E053D012139}~
~~
~MessageBox~
~{18FCC574-15D0-4D33-8BA9-0B7B41A9528E}~
~Random~
~Result = $result$~
~0~
~1~
~~
~Mathematics~
~{A90706C4-B9FC-4E8A-A35C-C65E44978871}~
~$max$~
~~
~15~
~result~
~Mathematics~
~{2A8A339E-C842-47A1-BE88-BDDF703DFF32}~
~99954654651~
~~
~14~
~~
~Comment~
~{D798BFCA-D4A5-42DF-8AB9-CB1B60ABB8C0}~
~This is producing zero each time (regardless of seed value).~
~Comment~
~{0799E681-68DD-4B58-B796-0A45533BA54A}~
~~
~Comment~
~{98242BCC-05CD-48F7-B19B-F6CC91018CE3}~
~~
~MessageBox~
~{646A62B2-0FD1-49F1-974D-4B79B9A58AE6}~
~Random~
~Result = $result$~
~0~
~1~
~~
~Mathematics~
~{3CDEE681-7F50-44CE-973E-A742CB53B45C}~
~$max$~
~~
~15~
~result~
~Comment~
~{129E26A9-CE61-47F1-B104-4B02BE7F45B4}~
~This will generate 0 each time using default settings~
~Comment~
~{65E33608-6C58-4152-96A8-2E0AE900FF32}~
~~
~Set Variable~
~{4EC01694-2106-400F-BF90-6CBA9139B620}~
~min$MYAH$MYAH$FALSE~
~0~
~Comment~
~{FFBB3ACA-4F94-48B3-A325-493399179172}~
~Minimum value:~
~Comment~
~{A56840E1-609C-4A67-BCD4-6BB9FE560C21}~
~~
~Set Variable~
~{6B816C0C-9863-4B57-9D94-46803780A47B}~
~max$MYAH$MYAH$FALSE~
~9223000000000000000~
~Comment~
~{002172C8-762C-4C71-B7A3-F0271D795F7F}~
~roughly the largest possible value:~
~Comment~
~{6EE85624-21B9-40E6-BA61-E641CAF23EFA}~
~~
~Set Variable~
~{61813DEF-3AC4-4783-8083-1C6BCFD9EA54}~
~result$MYAH$MYAH$FALSE~
~~
~Comment~
~{FA9FC070-5138-4CD8-9EDE-0E51DECF8524}~
~stores the result of operations:~

Re: Random numbers.

Posted: Thu Nov 11, 2010 2:28 am
by bokkie
mills wrote:I'm not sure if the Generate Random Number command is supposed to actually generate a random number.
Andy,

You can see our confusion as the clue to its intended use is in the name! :D

Anyway, I'll leave it at that as I think I have another option and that's to use a C# console application and I'll write that into a FileBag and call it when I need it. I can then use .Net's Random object to return an appropriate value back to my script. Sorry to have wasted your time in this respect but it's been quite revealing and defnitely something I can add to my knowledge base.

Re: Random numbers.

Posted: Thu Nov 11, 2010 2:41 am
by mills
No time wasted at all. Luckily I had my notes ready for this conversation. :D

At least I feel like this random number behavior is fully documented now (I left out that zero is returned for those outlying results). Thank you!