You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a real BLOCKER but I hope easy to fix ? I need randoms that change from run-to-run. Our LPython random produces the same result every run.
fromrandomimportrandomprint(random()) ########### PRODUCES SAME RESULT EVERY RUN ########### BUT, how to seed with time-of-day or internet noise# or some other sort of variable entropy?# NO WORK from random import seed
from lpython import init_random
from random import random
init_random()
print(random())
Where the init_random function is our own function, doing nothing in CPython mode, but initializing the random number generator for LPython mode. That should unblock Brian.
Later we can figure out whether to call init_random() automatically in the main program and whether to always call it, or only if the user calls random, etc. (I think CPython somehow initializes the random number generator automatically). That's lower priority.
Let init_random have an optional argument (or something like that) so I can seed the RNG for the cases where I do not want entropy, i.e., where I do want deterministic pseudorandoms.
On Wed, Jul 5, 2023 at 1:29 PM Ondřej Čertík ***@***.***> wrote:
As a quick fix, let's do:
from lpython import init_random
from random import random
init_random()
print(random())
Where the init_random function is our own function, doing nothing in
CPython mode, but initializing the random number generator for LPython
mode. That should unblock Brian.
Later we can figure out whether to call init_random() automatically in
the main program and whether to always call it, or only if the user calls
random, etc. That's lower priority.
—
Reply to this email directly, view it on GitHub
<#2110 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABSRRZ4CVN3HBASK4WSO4DXOXFEPANCNFSM6AAAAAAZ7MNVHU>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
Hello, I was thinking of grabbing this issue, and I already thought of a way of doing so with C++ random. I already have the code inside libasr in rng.cpp, but can't link it correctly.
I set the SRC in CMakeLists.txt to include my file and exported it with extern "C" , but still doesn't work.
Activity
certik commentedon Jul 5, 2023
As a quick fix, let's do:
Where the
init_randomfunction is our own function, doing nothing in CPython mode, but initializing the random number generator for LPython mode. That should unblock Brian.Later we can figure out whether to call
init_random()automatically in the main program and whether to always call it, or only if the user calls random, etc. (I think CPython somehow initializes the random number generator automatically). That's lower priority.rebcabin commentedon Jul 5, 2023
Let init_random have an optional argument (or something like that) so I can seed the RNG for the cases where I do not want entropy, i.e., where I do want deterministic pseudorandoms.
rebcabin commentedon Jul 6, 2023
OmarMesqq commentedon Sep 9, 2023
Hello, I was thinking of grabbing this issue, and I already thought of a way of doing so with C++
random. I already have the code insidelibasrinrng.cpp, but can't link it correctly.I set the
SRCinCMakeLists.txtto include my file and exported it withextern "C", but still doesn't work.Anyone got any tips?
certik commentedon Sep 10, 2023
@OmarMesqq go ahead and submit a PR with what you have, and then we'll help improve it.
certik commentedon Sep 23, 2023
I think @rebcabin is not blocked by this anymore, so I removed the BLOCKER tag.
certik commentedon Oct 17, 2023
This issue will be fixed by #2318.
There is another issue that the random numbers do not appear random, which is a separate issue: #2382.