Random Number Generator does not seem to work?

Got a problem you cannot solve? Try here.
Post Reply
SebSpiers
Posts: 38
Joined: Tue Dec 20, 2016 7:14 am
Location: Tewkesbury, UK

Random Number Generator does not seem to work?

Post by SebSpiers »

So the Random Number Generator doesn't seem to work, this is what I have done and it always returns the same number.

How do I generate a different 4 digit number every time???

Code: Select all

Set Variable rand to 
Set Random Number Generator Constants = 1983, 2002
Set Random Number Generator Seed = 1337
rand = Generate Random Number (max value 9999)
I'm not a developer, I just want to install things...
FrancescoT
Site Admin
Posts: 5361
Joined: Sun Aug 22, 2010 4:28 am

Re: Random Number Generator does not seem to work?

Post by FrancescoT »

Dear SebSpiers,

please have a look at the following link where the same question was already discussed.
viewtopic.php?f=2&t=10213&hilit=random+number

Regards
Francesco Toscano
InstallAware Software

White Papers (HowTos) - http://www.installaware.com/publication ... papers.htm
Publications - http://www.installaware.com/publications-review.htm
InstallAware Help -F1 anywhere in the InstallAware IDE
SebSpiers
Posts: 38
Joined: Tue Dec 20, 2016 7:14 am
Location: Tewkesbury, UK

Re: Random Number Generator does not seem to work?

Post by SebSpiers »

This doesn't make sense to me, why have a "Random Number Generator" which does not have the ability to generate random numbers???

What's wrong with a good old rand() function?!!

I don't want to pay for a Cryptography plugin. :? :? :?
I'm not a developer, I just want to install things...
FrancescoT
Site Admin
Posts: 5361
Joined: Sun Aug 22, 2010 4:28 am

Re: Random Number Generator does not seem to work?

Post by FrancescoT »

Dear SebSpiers,

In fact it's "rand()" that gets used internally and with "rand()" you need to set a unique "seed" for each random generation. Otherwise rand() returns each time the same identical number.
http://stackoverflow.com/questions/9459 ... ocess?rq=1

Hope this helps you.

Regards
Francesco Toscano
InstallAware Software

White Papers (HowTos) - http://www.installaware.com/publication ... papers.htm
Publications - http://www.installaware.com/publications-review.htm
InstallAware Help -F1 anywhere in the InstallAware IDE
SebSpiers
Posts: 38
Joined: Tue Dec 20, 2016 7:14 am
Location: Tewkesbury, UK

Re: Random Number Generator does not seem to work?

Post by SebSpiers »

So how do I generate a random seed? to be used by the Random Number Generator? :)
I'm not a developer, I just want to install things...
FrancescoT
Site Admin
Posts: 5361
Joined: Sun Aug 22, 2010 4:28 am

Re: Random Number Generator does not seem to work?

Post by FrancescoT »

Dear SebSpiers,

please see the Serial Validation sample for detailed real-world usage of these functions.

Alternatively, you may create a custom dll that returns a value based on the current system time.

Hope this helps you.

Regards
Francesco Toscano
InstallAware Software

White Papers (HowTos) - http://www.installaware.com/publication ... papers.htm
Publications - http://www.installaware.com/publications-review.htm
InstallAware Help -F1 anywhere in the InstallAware IDE
SebSpiers
Posts: 38
Joined: Tue Dec 20, 2016 7:14 am
Location: Tewkesbury, UK

Re: Random Number Generator does not seem to work?

Post by SebSpiers »

So I solved this by parsing the current time into 3 variables to give me a random number.

Code: Select all

Set Variable rand to 
Set Variable PARSETEMP to 
Set Variable const1 to 
Set Variable const2 to 
Set Variable const3 to 
Set Variable cTIME to $TIME$
Parse String $cTIME$ into Variables const1 and PARSETEMP (Split at first occurrence of pattern)
Parse String $PARSETEMP$ into Variables const2 and const3 (Split at first occurrence of pattern)
Set Random Number Generator Constants = $const2$, $const3$
Set Random Number Generator Seed = $const1$$const1$
rand = Generate Random Number (max value 9999)
I know I could have done this in less lines, but this is how I'm doing it currently, the variables cTIME and PARSETEMP are probably not necessary. :mrgreen:
I'm not a developer, I just want to install things...
Post Reply