Back to Recipes Homepage
recipe picture
Recipe: Random Number Generator
Created by Tlaloc 82 1799
3
Your rating: None Average: 3 (4 votes)
Used 41 times with an average impact of 182 points.

Profile

Name: Random Number Generator
ID: 2634
Created on: Wed, 06/02/2010 - 04:35
Updated on: Sat, 08/14/2010 - 05:07
Description:

Run this script and it will print random numbers to the output window. This is not meant to be a useful script by itself, but instead is a starting point for other scripts that need to do some randomization. It needs a seed, so it uses the least significant digits of the current score. If you rerun the script with no changes to the structure, it will generate the same sequence. Any change to the structure will show a different sequence. Feel free to use in your own scripts with credit and the copyright notice intact. See the comments in the script for more information.



Best For


Comments

Joined: 09/18/2009
Groups: SETI.Germany
Cool...

I had this idea to generate those numbers in a similar way.
Nice to see that there is already a script, so you saved some of my time and I don't need to reinvent the weel.

Thanks!

Tlaloc's picture
User offline. Last seen 17 weeks 3 days ago. Offline
Joined: 08/04/2008
Groups: Mojo Risin'
I made some changes

The random() function now works the same as the math.random() function in the standard lua library. In other words:

random() returns a fraction between 0 and 1
random(10) returns a random number between 1 and 10
random(10,20) returns a random number between 10 and 20, inclusive

you should call:

randomseed(getseed())

once before calling any random() functions, as this will seed the random number generator from the current score.

I removed all the comments from the random number generator itself (see the referenced site in the comments for a description of the algorithm). I added quite a bit a documentation about the functions themselves.

If the foldit people ever give us access to the math standard library, you should be able to replace all calls to random() with math.random(), and randomseed() with math.randomseed(), and get the same functionality. You can then then remove the code given here.

Zengief's picture
User offline. Last seen 9 years 3 weeks ago. Offline
Joined: 08/05/2010
Groups: None
perhaps request as feature

I can see using this as a stopgap measure, but I think a RNG should be a basic functionality of the language. And definitely easy to implement as well.

Nerro's picture
User offline. Last seen 8 years 44 weeks ago. Offline
Joined: 08/10/2010
Groups: None
Just an idea but isn't

Just an idea but isn't seeding by the time more logical? that way the same score generates 'more' unique numbers every time. Include the date and the result is effectively unique every time.

Did I miss something here?

Want to try?
Add to Cookbook!
To download recipes to your cookbook, you need to have the game client running.
Parent

none

Children
Authors
Sitemap

Developed by: UW Center for Game Science, UW Institute for Protein Design, Northeastern University, Vanderbilt University Meiler Lab, UC Davis
Supported by: DARPA, NSF, NIH, HHMI, Amazon, Microsoft, Adobe, RosettaCommons