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

Consider c-random? #783

Open
mrjbq7 opened this issue Feb 27, 2013 · 17 comments
Open

Consider c-random? #783

mrjbq7 opened this issue Feb 27, 2013 · 17 comments

Comments

@mrjbq7
Copy link
Member

mrjbq7 commented Feb 27, 2013

If we use the rand() from libc:

FUNCTION: int rand ( ) ;
SINGLETON: c-random
M: c-random random-32* drop rand ;

It's faster than the mersenne-twister that we use by default:

IN: scratchpad 10,000,000 iota >array

IN: scratchpad c-random [ gc [ randomize ] time ] with-random
Running time: 2.38198561 seconds

IN: scratchpad gc [ randomize ] time
Running time: 2.666762887 seconds
@mrjbq7
Copy link
Member Author

mrjbq7 commented Feb 27, 2013

See d66fdbb.

@mrjbq7
Copy link
Member Author

mrjbq7 commented Feb 8, 2014

The rand() function has RAND_MAX of 2^31-1, which is not quite the same as our random-32* which has max value of 2^32-2. Calling it twice to get one more bit of randomness reduces the performance advantage considerably.

@bjourne
Copy link
Member

bjourne commented Feb 9, 2014

The difference is even less pronounced on my (linux) machine:

IN: scratchpad gc [ randomize ] time
Running time: 1.222153295 seconds
IN: scratchpad c-random [ gc [ randomize ] time ] with-random
Running time: 1.160819849 seconds

I wouldn't be suprised if factor outperforms windows libc's rand() function.

@bjourne
Copy link
Member

bjourne commented Feb 10, 2014

Nope, the difference is bigger on windows:

IN: scratchpad gc [ randomize ] time
Running time: 1.425305261 seconds
IN: scratchpad c-random [ gc [ randomize ] time ] with-random
Running time: 1.14878115 seconds

The rand() function works exactly the same on windows and linux so the random.c vocab doesn't need to be exclusive to unix.

@erg erg added the performance label Nov 9, 2014
@erg
Copy link
Member

erg commented Aug 5, 2015

The good RNG is PCG:

http://www.pcg-random.org/

@erg erg added the crypto label Aug 5, 2015
@mrjbq7 mrjbq7 modified the milestones: 0.98, 0.99 Sep 22, 2015
@erg erg added the libc label Jun 24, 2017
@alex-ilin
Copy link
Member

I looked through the help-wanted issues, and this one caught my eye, since I like crypto and stuff.
I have a question, though. If I implement it, how will it be used? I mean, should I implement it in Factor, or in C++ of the VM?

@mrjbq7
Copy link
Member Author

mrjbq7 commented Jan 3, 2022 via email

@alex-ilin
Copy link
Member

Should I change the issue title to "Implement PCG RNG"?

@mrjbq7
Copy link
Member Author

mrjbq7 commented Jan 3, 2022 via email

@alex-ilin
Copy link
Member

If I open a new issue, did I resolve a help-wanted issue or created a new one?

@mrjbq7
Copy link
Member Author

mrjbq7 commented Jan 3, 2022 via email

@alex-ilin
Copy link
Member

alex-ilin commented Jan 3, 2022

I mean, if my goal was to reduce the open issue count, what should I have done to close this one?
Should it maybe be closed already with no action?

@mrjbq7
Copy link
Member Author

mrjbq7 commented Jan 3, 2022 via email

@alex-ilin
Copy link
Member

Some critical comments about the PCG MWC: rust-random/rngs#18

@alex-ilin
Copy link
Member

Added PR #2542 with the PCG MWC implementation.

@erg
Copy link
Member

erg commented Jan 7, 2022

Related to #1518

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants