Comments on: Help me get random numbers by mental arithmetic.
http://ask.metafilter.com/191135/Help-me-get-random-numbers-by-mental-arithmetic/
Comments on Ask MetaFilter post Help me get random numbers by mental arithmetic.Tue, 19 Jul 2011 08:07:51 -0800Tue, 19 Jul 2011 08:17:17 -0800en-ushttp://blogs.law.harvard.edu/tech/rss60Question: Help me get random numbers by mental arithmetic.
http://ask.metafilter.com/191135/Help-me-get-random-numbers-by-mental-arithmetic
I would like a pseudo-random number generation algorithm that I can calculate in my head. <br /><br /> So often when I'm out and about I find myself in desperate need of some random numbers! For example, I often want to have randomly varying intervals of time when exercising or giving rewards during dog training. I would like to be able to generate a sequence of pseudo-random numbers just by mental arithmetic. To be specific, let's say that the number should be uniformly distributed between 1 and 10 (although if there are easy ways to vary the interval, that would be great). Math & algorithm experts, can you suggest a suitable algorithm?<br>
<br>
Please don't suggest that I roll a die or use my phone or do anything else that involves my hands, because I'm using my hands for dog training/exercise/whatever. Also I like mental arithmetic: doing some calculations in my head is part of what will make this fun.post:ask.metafilter.com,2011:site.191135Tue, 19 Jul 2011 08:07:51 -0800medusarandomnumberspseudorandomalgorithmmentalarithmeticgeekinessfunBy: k5.user
http://ask.metafilter.com/191135/Help-me-get-random-numbers-by-mental-arithmetic#2750727
Knuth has a bit to say about RNGs and gives a few simple algorithms in his books.. <a href="http://en.wikipedia.org/wiki/Linear_congruential_generator"> Wiki</a> gives the general form of an algorithm and inputs for it ..comment:ask.metafilter.com,2011:site.191135-2750727Tue, 19 Jul 2011 08:17:17 -0800k5.userBy: RustyBrooks
http://ask.metafilter.com/191135/Help-me-get-random-numbers-by-mental-arithmetic#2750740
The most common way in poker is to use the second hand on your wrist-watch - does that fall under the same category as rolling a die or using your phone?comment:ask.metafilter.com,2011:site.191135-2750740Tue, 19 Jul 2011 08:22:40 -0800RustyBrooksBy: mauvest
http://ask.metafilter.com/191135/Help-me-get-random-numbers-by-mental-arithmetic#2750748
Does <a href="http://ask.metafilter.com/20334/Random-sequences-in-your-head">this thread</a> help?comment:ask.metafilter.com,2011:site.191135-2750748Tue, 19 Jul 2011 08:27:06 -0800mauvestBy: advicepig
http://ask.metafilter.com/191135/Help-me-get-random-numbers-by-mental-arithmetic#2750814
You could memorize the first 60 digits of pi and use the second hand on your watch to choose which digit to select. (or substitute your favorite irrational number.)comment:ask.metafilter.com,2011:site.191135-2750814Tue, 19 Jul 2011 08:55:37 -0800advicepigBy: alby
http://ask.metafilter.com/191135/Help-me-get-random-numbers-by-mental-arithmetic#2750829
What you really need is a way to generate bits.<br>
<br>
When you've worked out a way to do that you can generate as many bits as you need to generate a number as large as you want. This has the advantage of involving even more mental arithmetic.<br>
<br>
For example, if you wanted to generate a number between 0 and 59 you would need to generate 6 bits (this would technically give you a number up to 63).<br>
<br>
How you generate the bits is the difficult part. I would suggest counting objects and assigning odd and even numbers to the ones and zeroes.<br>
<br>
<blockquote>"I see three trees, so first bit is 1, two birds so second bit is 0, nine clouds so third bit is 1, seven people so fourth bit is 1, four potholes so fifth bit is 0 and five cars so sixth bit is 1."</blockquote><br>
<br>
101101 in binary = 45 in decimalcomment:ask.metafilter.com,2011:site.191135-2750829Tue, 19 Jul 2011 09:08:57 -0800albyBy: Rat Spatula
http://ask.metafilter.com/191135/Help-me-get-random-numbers-by-mental-arithmetic#2750833
Multiply <code>x</code> by <code>a</code>, add <code>c</code>, divide by <code>m</code> and take the remainder. Then do it <a href="http://en.wikipedia.org/wiki/Linear_congruential_generator">again and again and again</a>.comment:ask.metafilter.com,2011:site.191135-2750833Tue, 19 Jul 2011 09:12:01 -0800Rat SpatulaBy: zengargoyle
http://ask.metafilter.com/191135/Help-me-get-random-numbers-by-mental-arithmetic#2750858
Pick a random large number, divide by 7, keep remainder for 0-6, choose a big enough number so you can take the remainder-eth digit of the quotient for 0-9.comment:ask.metafilter.com,2011:site.191135-2750858Tue, 19 Jul 2011 09:20:27 -0800zengargoyleBy: A Thousand Baited Hooks
http://ask.metafilter.com/191135/Help-me-get-random-numbers-by-mental-arithmetic#2750870
Close your eyes for a moment. Open them. Name the first thing you see. Count the position in the alphabet of each letter in the name and add them all up. Divide the sum by the interval you want; the remainder is your pseudorandom number.comment:ask.metafilter.com,2011:site.191135-2750870Tue, 19 Jul 2011 09:29:22 -0800A Thousand Baited HooksBy: A Thousand Baited Hooks
http://ask.metafilter.com/191135/Help-me-get-random-numbers-by-mental-arithmetic#2750921
Sorry, that should of course be "the remainder plus one is your pseudorandom number".comment:ask.metafilter.com,2011:site.191135-2750921Tue, 19 Jul 2011 10:04:59 -0800A Thousand Baited HooksBy: madcaptenor
http://ask.metafilter.com/191135/Help-me-get-random-numbers-by-mental-arithmetic#2750945
advicepig: using the first 60 digits of pi don't give a uniform distribution: they are<br>
<br>
14159 26535 89793 23846 26433 83279 50288 41971 69399 37510 58209 74944 <br>
<br>
and so contains 3 0s, 5 1s, 6 2s, 8 3s, 7 4s, 6 5s, 4 6s, 5 7s, 6 8s, 10 9s. This amount of deviation from uniformity is not unexpected but could be a bit of a problem.<br>
<br>
medusa: the second hand on your watch works, as RustyBrooks has suggested. If you want random numbers between 0 and n-1 you can take the remainder upon dividing the number of seconds by n. You'll get a uniform distribution as long as n is a factor of 60 - and 60 has lots of factors.comment:ask.metafilter.com,2011:site.191135-2750945Tue, 19 Jul 2011 10:19:57 -0800madcaptenorBy: IAmBroom
http://ask.metafilter.com/191135/Help-me-get-random-numbers-by-mental-arithmetic#2751016
<em>advicepig: using the first 60 digits of pi don't give a uniform distribution<br>
</em><br>
madcaptenor, the OP didn't ask for a uniform distribution. But if he wanted one, then the idea from A Thousand Baited Hooks fails as well:<br>
<br>
<em>Close your eyes for a moment. Open them. Name the first thing you see. Count the position in the alphabet of each letter in the name...</em><br>
<br>
A-things are much more common than Q-things.<br>
<br>
--<br>
<br>
My solution (and I've used it in similar situations: build a text file of <a href="http://www.fourmilab.ch/hotbits/">random numbers</a> (<a href="http://www.metafilter.com/79015/Genuine-random-numbers-generated-by-radioactive-decay">previously</a> on The Blue). Before you leave, memorize as many as you need. Unfortunately, this leaves out the math-in-your-head fun.comment:ask.metafilter.com,2011:site.191135-2751016Tue, 19 Jul 2011 11:09:15 -0800IAmBroomBy: chairface
http://ask.metafilter.com/191135/Help-me-get-random-numbers-by-mental-arithmetic#2751042
It's a hard thing to do with computers, never mind your squishy think-meats. The easiest one in use is the <a href="http://en.wikipedia.org/wiki/Linear_congruential_generator">linear congruential generator</a>. LCG's typically are poor though, with low periodicity and obvious flaws like odd/even toggles. Still, you could probably pick a random number 0-99 in your head, then use and add and multiply steps to get the next number, and use the tens digit of that to get a 0-9 reasonably random number.<br>
<br>
Picking your constants for adding (c) and multiplying (a) is the only hard part. Pick two and stick with them, as they need to have certain properties to guarantee a complete cycle over m.<br>
<br>
Let's try an easy example. c is 11, and a is 7 (primes usually work well with LCGs).<br>
<br>
You pick 86 in your head. Add 11, get 97. Multiply by seven and you'd get 679. Modulo 100, your next number would be 79. As mentioned, the low digit tends to be utter crap so use the 7.<br>
<br>
If you keep this up, you'll eventually memorize all the possible 100 outputs. So you can change a and/or c again.<br>
<br>
This being the internet, I assume corrections and criticisms will quickly follow.comment:ask.metafilter.com,2011:site.191135-2751042Tue, 19 Jul 2011 11:26:46 -0800chairfaceBy: contrarian
http://ask.metafilter.com/191135/Help-me-get-random-numbers-by-mental-arithmetic#2751108
Fibonacci sequences are an only-moderately-bad pseudorandom number generator. If you can remember the last two values across a matter of days (maybe write them down when your hands are free or something), then you can probably find a sequence with a long enough period that doing it in your head you will never get repeats.<br>
<br>
I would not recommend doing anything where randomness is really important with this -- in software there are much better alternatives. But Fibonacci is relatively easy to do mentally, and gives decently random results.comment:ask.metafilter.com,2011:site.191135-2751108Tue, 19 Jul 2011 12:09:16 -0800contrarianBy: madcaptenor
http://ask.metafilter.com/191135/Help-me-get-random-numbers-by-mental-arithmetic#2751116
<i>A-things are much more common than Q-things.</i><br>
<br>
Yes, but you're not just looking at the first letter.comment:ask.metafilter.com,2011:site.191135-2751116Tue, 19 Jul 2011 12:13:13 -0800madcaptenorBy: pla
http://ask.metafilter.com/191135/Help-me-get-random-numbers-by-mental-arithmetic#2751540
Virtually all the algorithmic generators require modulo division, which you <i>can</i> do in your head, but most people really really suck at it.<br>
<br>
I'd have to second the "second-hand"-as-an-index-to-Pi approach. It seems like the most realistic option (unless you <i>really</i> like division).comment:ask.metafilter.com,2011:site.191135-2751540Tue, 19 Jul 2011 17:01:13 -0800plaBy: chrisamiller
http://ask.metafilter.com/191135/Help-me-get-random-numbers-by-mental-arithmetic#2751806
<em>Close your eyes for a moment. Open them. Name the first thing you see. Count the position in the alphabet of each letter in the name and add them all up. Divide the sum by the interval you want; the remainder is your pseudorandom number.<br>
</em><br>
<br>
I was curoius as to whether this would actually provide a uniform distribution, so I checked it out. I piped /etc/dictionaries-common/words into a little script that calculated the sum and took modulo 10, then <a href="http://i.imgur.com/VReTq.png">plotted the results with R</a>.<br>
<br>
I'll be damned. This would actually work pretty darn well.comment:ask.metafilter.com,2011:site.191135-2751806Tue, 19 Jul 2011 20:40:32 -0800chrisamillerBy: A Thousand Baited Hooks
http://ask.metafilter.com/191135/Help-me-get-random-numbers-by-mental-arithmetic#2752041
Heh. I was pretty sure there'd be enough entropy in the word samples to give a reasonably smooth distribution; thanks for confirming my hunch.comment:ask.metafilter.com,2011:site.191135-2752041Tue, 19 Jul 2011 23:46:36 -0800A Thousand Baited HooksBy: IAmBroom
http://ask.metafilter.com/191135/Help-me-get-random-numbers-by-mental-arithmetic#2752937
<em>I was curoius as to whether this would actually provide a uniform distribution, so I checked it out. I piped /etc/dictionaries-common/words into a little script that calculated the sum and took modulo 10, then plotted the results with R.<br>
<br>
I'll be damned. This would actually work pretty darn well.<br>
</em><br>
I'll be damned, too, chrisamiller. Completely unexpected, as it doesn't matter how many letters you take: their distribution still isn't uniform.<br>
<br>
I wonder if this is some odd by-product (no pun intended) of regression to the mean. Weird, at any rate.comment:ask.metafilter.com,2011:site.191135-2752937Wed, 20 Jul 2011 13:28:45 -0800IAmBroom