Random Number Generator does not seem to work?

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

Random Number Generator does not seem to work?

Postby SebSpiers » Thu Dec 22, 2016 7:34 am

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?

Postby FrancescoT » Thu Dec 22, 2016 10:17 am

Dear SebSpiers,

please have a look at the following link where the same question was already discussed.
https://www.installaware.com/forums/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?

Postby SebSpiers » Thu Dec 22, 2016 10:47 am

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?

Postby FrancescoT » Thu Dec 22, 2016 11:29 am

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/9459035/c-rand-gives-same-number-when-running-process?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?

Postby SebSpiers » Fri Dec 23, 2016 4:10 am

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?

Postby FrancescoT » Fri Dec 23, 2016 6:48 am

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?

Postby SebSpiers » Tue Jan 10, 2017 6:49 am

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...


Return to “Technical Support”

Who is online

Users browsing this forum: No registered users and 26 guests