Retrieving "true" random values from web lookup

Hey DynamoTeers…
I was wondering if anyone have had any luck pullling data from one of the websites delivering “true” randomity? -I don’t need cryptographic strong values, as this method can deliver, but i’d like to not have to change the seed myself everytime i run my graph.
Any suggestions or examples are welcome, i’ll get back to you guys soon :slight_smile:
Regards
Tue

1 Like

Math.Random (the one with no seed) and Math.RandomList should give you a true random value, at least we’ll enough for 99% of uses. I have used them extensively and have yet to see a duplicate (though in thousands of runs I may have missed one). I believe that I t’s route implementation is based on Donald E. Knuth’s subtractive random number generator algorithm.

You could also use Python ‘s random module. It’s underlaying tech is based on the Mersenne Twister algorithm.

But as you likely learned in finding ‘true’ random number generators online, all of these are deterministic. This is even true for many cryptographically secure generators - such as the one built into your OS, which likely uses a few seeds determined by your current environment (date and time, thread id, process id, time since booting up, and hashed values of string identifiers like username, pc name, folder name, etc.). True random only happens outside of the cpu.

So the question becomes ‘how random is close enough for your use. This blog post has a quick analysis in image form and some c# code to allow you to experiment on your own. If those numbers look random enough for you, likely there is no need for finding a true random, but instead a way to automatically kick off a new random on each subsequent run.

I believe that this bit of design script will help with the later, however it will still require toggling a trigger each time you want a new number (similar to making a web call for a true random number).

def UpdatingRandom(trigger)
{
    return Math.Random();
};
UpdatingRandom(trigger);

Hi Jacob, thx so much for answering my post. As alway; i should have been more precise. I guess my main aim is to be able to run my script again and again without manually changing the seed value by hand for every new run. And i thought it nice to just grab randomity from the web.
But your post got me thinking, that i could just pull the seed from my system time+date, that would be a new number for each run? -Will look into that.
-Or i could just create a loop that changes the value of the seed by adding +1 to previous value for every run, but i’m not skilled enough to do that either…

(-the graph is simply about about rotating hexagon truchet tiles in a random fashion, to generate unique patterns. Randomness only needed for my own pleasure :slight_smile: )

The DesignScript definition I posted above will give you the random value any time the input (trigger) is changed. As such you can use a periodic run and a DateTime.Now() node, or just changing a file you read and write to on each run should trigger new values.

However I don’t necessarily recommend forcing a random every time as when you want to ‘keep’ a result you can’t trigger that unless you record them all. Deciding when to trigger each new random value is usually more effective. Well that or leverage Generative Design for the task. :slight_smile:

It Works!


-Thanks, Jacob.
Project and dyn graph for laughs:
truchet_tiles.rvt (1.2 MB)
truchet_tiling_ROTATION.dyn (33.6 KB)

3 Likes

This is a beautiful example of application of random within a system! Excellent work!

1 Like

Thank you so much, Jacob.
As a seasoned veteran of the Building Industry, i’ll have to reply, that constructing and managing a “house” is all about “random within a system”. From the top down. Not to point finges, but this industry is shit.
What i want to do now, is teach my students is to ocontrol randomity with data management, but that’s a whole other story.
I’ll get back to you guys on accessing web API’s to gather IoT RaspberryPi data, and bring them back into the model, realtime. You haven’t seen the last of me. @sovitek will give a hand.
Again, Jacob , thx for the help! -happy days, be good, do well…

1 Like

heheh selvfølgelig min ven :wink: see you tomorrow