Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rnd Function Fix #42

Open
malvidin opened this issue Jul 22, 2022 · 1 comment
Open

Rnd Function Fix #42

malvidin opened this issue Jul 22, 2022 · 1 comment

Comments

@malvidin
Copy link

The Rnd function does not return 71 if Randomize is not called.

Steps to reproduce the behavior:
Execute script:

intHighNumber = 100
intLowNumber = 1

intNumber = Int((intHighNumber – intLowNumber + 1) * Rnd + intLowNumber)
Wscript.Echo intNumber

71 should be returned, unless Randomize is called before Rnd.

https://devblogs.microsoft.com/scripting/how-can-i-generate-random-numbers-using-a-script/

@malvidin
Copy link
Author

malvidin commented Jul 22, 2022

Rnd in vba_library.py could use a rnd = random.Random() from the VBA context with an initial seed like rnd.seed(0.3477367247528699) (Python3), which would return a similar initial value. It would take more searching to get a seed that would emulate subsequent Rnd calls. Randomize could then set a new rnd = random.Random() for subsequent calls in that context.

Using a list of actual Rnd values from VBScript could be added as a list. It is simpler, but Rnd calls after the list is exhausted would not be consistent.

[0.7055475, 0.533424, 0.5795186, 0.2895625, 0.301948, 0.7747401, 0.01401764, 0.7607236, 0.81449, 0.7090379]

This was referenced Jul 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant