Ask Lemmy
A Fediverse community for open-ended, thought provoking questions
Please don't post about US Politics. If you need to do this, try !politicaldiscussion@lemmy.world
Rules: (interactive)
1) Be nice and; have fun
Doxxing, trolling, sealioning, racism, and toxicity are not welcomed in AskLemmy. Remember what your mother said: if you can't say something nice, don't say anything at all. In addition, the site-wide Lemmy.world terms of service also apply here. Please familiarize yourself with them
2) All posts must end with a '?'
This is sort of like Jeopardy. Please phrase all post titles in the form of a proper question ending with ?
3) No spam
Please do not flood the community with nonsense. Actual suspected spammers will be banned on site. No astroturfing.
4) NSFW is okay, within reason
Just remember to tag posts with either a content warning or a [NSFW] tag. Overtly sexual posts are not allowed, please direct them to either !asklemmyafterdark@lemmy.world or !asklemmynsfw@lemmynsfw.com.
NSFW comments should be restricted to posts tagged [NSFW].
5) This is not a support community.
It is not a place for 'how do I?', type questions.
If you have any questions regarding the site itself or would like to report a community, please direct them to Lemmy.world Support or email info@lemmy.world. For other questions check our partnered communities list, or use the search function.
Reminder: The terms of service apply here too.
Partnered Communities:
Logo design credit goes to: tubbadu
view the rest of the comments
I see a lot of good answers here but let’s try it from another angle.
How do we get randomness from a function or formula?
For starters let’s setup a few simple rules.
Every time our random function is called we’ll
So let’s call it.
X is now 6
X is now 7
X is now 7
LAST_RESULT is now 7
Ok. So let’s call it again
X is now 24
X is now 16
X is now 2
LAST_RESULT is now 2
And if we call it again we get seemingly random results
But the next time you run it you’ll get the same results in the same order. 7, then 2 then 4 then 3
So what you need is something to “seed” the random number calculation.
Something like
Then when you call Random after this it starts with that as the prior results and gives seemingly random results.
Of course my calculations are rough and probably fail/repeat after so many calls but it gives you an idea of how this works.
So the trick is to get noise for the seed. That could be the number of non leap seconds since 00:00:00 UTC on Thursday, 1 January 1970 (Unix epoch)
Or the temperature reading of a CPU chip.
Maybe it’s the ratio of red vs yellow from a camera feed looking at lava lamps.
Or the current users average typing speed.
An additional note. Many of those would not be “cryptographically” secure for encryption because they can easily be determined by a third party. We all experience the same “Unix epoch” within a few milliseconds if our system clocks are properly set for example. Or monitored from afar and reproduced (hacked webcam shows they had just typed the following letters in the previous 27 seconds that we know the “algorithm” uses, etc.