Files
hpr-knowledge-base/hpr_transcripts/hpr2168.txt

388 lines
32 KiB
Plaintext
Raw Normal View History

Episode: 2168
Title: HPR2168: Analogue Random Number Generation
Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr2168/hpr2168.mp3
Transcribed: 2025-10-18 15:13:39
---
This is HPR episode 2168 entitled Adalod Random Humber Generation.
It is hosted by Klaatu and is about 42 minutes long.
The summary is Klaatu Pandam Adalod Random Humber Generation.
This episode of HPR is brought to you by AnanasThost.com.
Get 15% discount on all shared hosting with the offer code HPR15.
That's HPR15.
Better web hosting that's honest and fair at AnanasThost.com.
Hey everyone, this is Klaatu.
You're listening to HPR15.com public radio.
And today I want to talk about random numbers.
I don't know of many Linux geeks who are interested in sort of maintaining their system
and maybe dappling and programming who are not also obsessed at least mildly.
Is that a thing?
mild obsession with random numbers.
Random numbers are kind of something at least in my experience.
And this may have just been me.
But in my experience it's something that's one of those things that you get
introduced to pretty early on in your Linux exploration.
Usually by way of stupid new tricks, you know, kind of like,
look, you can pipe dev random to your sound device and make funny sounds.
You know, and that's your first introduction to this concept of oh, by the way,
it's not possible to produce random numbers on a computer.
And that kind of, it's a mind-blowing thing when you kind of realize what the implications to
this dev random thing really are.
You kind of, it kind of blows your mind.
Certainly I'd never before discovering that dev random was a thing.
I certainly did not know that you could not produce random numbers from a computer,
but that you could get close enough to it.
You could do pseudo-random.
And then there's that, that question of, well,
can we even produce random numbers at all?
Like, how does one do that with or without a computer?
It's just like, how does one come up with a random idea?
A random thought, a random number?
How does that happen?
Can it happen?
And it's like this really sort of interesting big topic
that I absolutely have no authority to go into whatsoever.
I mean, it's a really interesting topic.
And I've actually heard I got to sit in while two mathematicians were discussing
that concept, and it was like the most interesting 15 minutes of my life.
Probably it was a really, really fascinating stuff.
But I mean, it only, it probably wasn't even a full 15 minutes.
It was probably more like five minutes.
And then they started talking about things I didn't even,
I couldn't even begin to comprehend.
So yeah, it's a really fascinating subject.
And that's not what I'm talking about here.
I'm really just talking about this idea of producing random,
a random sequence of numbers without,
well, without a computer really is what I'm going to get to.
So certainly without, with a computer, it's difficult enough.
But for most people looking at slash dev, slash random,
or you random, or whatever, is good enough, close enough.
That's random enough.
It certainly is for me.
I've never, I have yet to be at a place where that's not good enough for me.
So that's great.
And Python has a random function, random.rand.
And you can use that.
And for most programming purposes, again, that's good enough.
It generates some random numbers.
In fact, the, I mean, there are other ways to do that.
The first, the first program exercise that I really kind of
task myself with when I'm learning or trying to learn a different programming language
is a dice rolling application.
I just, I find that to be an interesting sort of thing to
approach. And I used this in classes where I've taught people bash and Python.
Because it really gets you thinking about where, how can you, how do you generate data?
How, what are your sources of data?
Like, what, how can you get that?
And usually I pose that in the, in the two times that I've done this with other people.
I pose that to them and ask them, we want to produce a random number so that the computer,
the AI, has a dice roll that can compete with our dice roll.
And how can we get that?
What, where do numbers come from in real life?
And they eventually usually get to the subject of time.
And then you can kind of whittle that down into the seconds.
And the different ways to, to get a timestamp from the computer and then the different ways to
parse that timestamp such that it's within a certain range.
And sometimes that leads to mathematical things like, okay, well, how do we do a log 10 of this
number or how do we just do division of this number or whatever?
So yeah, it's kind of, kind of a good exercise.
And then you can also get into object oriented stuff where you're actually defining the sides of the
die. So that you're then sort of defining the range of the, the number that you want to return.
It's a good exercise, I think.
And that's where the computer and usually that's good enough.
So I'm not, I'm not fussed about whether or not I'm getting true random, even pseudo random.
I really couldn't care less.
It's more just like on the spot, can you predict the next number I'm going to, I'm going to say three.
The traditional way to do that is a roll dice.
That's a pretty, pretty time honored and pretty, pretty, pretty reliable way to kind of get
an unpredictable result pretty quickly. And the simpler version of that is flipping a coin.
That starts to get dangerous because you really do start to feel like you're approaching
predictability because there is that 50, 50 chance. So it's just kind of like, well,
I'm going to get enough right that I'm going to start doubting whether this is random enough.
And I think that's the catch right there is like, I honestly believe this that in terms of
producing a quote, random enough number, well, random enough, unquote, number is really based on
on feeling. It's inside of us all. No, but really, it's like, it's whether you believe
it's random enough or not, really. Because certainly, if you dop yourself into thinking
that you're producing non-random numbers, then at least I start to sort of, I call shenanigans
on myself, you know, I think, well, this isn't really random. I can predict this.
Even if I can't predict it, the times that I can't predict it become the exception
to the times that I happen to be correct. So flipping a coin, certainly, if I do that three times,
and I predict two out of three, then in my mind, that was not a random enough,
that wasn't a random enough experience. That was too predictable, which is weird because you
kind of like, you're basing random enough on how often you fail, which, I mean, part of being
random enough is that you're not always going to fail. So sometimes you are going to succeed,
and that's fair. But as I say, I think there's like that, I guess it would be an uncanny valley type
of threshold where it's random enough, random enough, random enough, because I'm kind of feeling like
I get some, I lose some, but then if I start, if it starts going in one way, and usually in my
experience that's success, then it starts to feel like this is no longer random. Again, that could be
me. I would be interested in hearing other people's sort of experiences of that.
So the problem is, what happens if you don't have dice? Because in some social situations,
it's not, apparently, what I'm told, it's not appropriate to sit there and obsessively
roll dice while people are holding a business meeting or having dinner or really doing anything.
So sometimes dice is not really a possibility or a coin flipping. You start to look like your
two-face or something and just kind of like trying to be cool. It's not something that you can
necessarily do. So I started looking for ways to produce random numbers without dice, without a
coin toss, and ideally without something that is a dead giveaway that, hi, I'm not listening to
you right now, I'm actually producing random numbers in my head. So the first way that I figured
on doing this was just extracting them from my environment. And that's if you're in room and
you're bored, just kind of choose something. If there's a person there and then look at the person,
look at there, I don't know, they're right sock. What color is it? Assign the color, a name with
normal English words. So let's say there, it's a red sock. Red has three letters in it. I just produced
the number three, fairly randomly. And then I might look at something else and produce a different
number. The problem with that is, I mean, that does work. The problem I've had with that is that,
at least again, for me, I start to fixate on things. And once I've come up with one method of
generating a number, that's how I start generating numbers no matter what, you know, like so right there,
I just, I gave an example of trying to find a color on a pseudo random object and then counting
the characters in the colors name. And that's fine, but then at least my tendency is then to start
looking at all objects in the room, extracting their color, the name of their color,
predominant color, and then giving the number, you know, and their just colors don't, the names of
colors don't really vary that much, you know, it's about three, a lot of four letters, some five,
probably some six, but you know, that's kind of your range, it's like three to six, pretty much.
If I knew more color names, like if I was one of those graphic designer types who had gone to like
art school for graphic design, I might know fancier colors and I might be able to, to say,
you know, well, that's more of a maw of or a fuchsia or a turquoise. I probably wouldn't say turquoise
because nobody knows how to spell turquoise. So what's that other one? Starts with a tea. Anyway,
you can come up with fancy names and then maybe you get more, maybe you get more of a variable.
Either way, I feel like I really lock myself in to sort of like the first method that I invent,
then becomes the only method I can, I can use and it becomes kind of, I lock myself in.
So that's a little bit, that's a little bit dicey. So the other another way to generate random
numbers while you're sitting around doing nothing is, you know, just like if you have a magazine
or a book or something, open it to a random page. And when I say random, I say flip through the
the the the book and then stop on a page at some point. And then before you look at the page,
think of a number, you know, whatever number you want really, probably, probably up to 20 would be fine.
0 through or 1 through 20. And then and then look at the page count, count over each word to
the 20th word or whatever you chose, let's say we chose 20. So count down to 20 words, look at the
word that you get. And again, just count the letters or assign number values to each letter based
on the alphabet and add those up, you know, it all obviously depends on the range of number that
you want. Or you could just take the first letter of the 20th word or whatever number you chose
and and assign that a numeric value based on its alphabetic position. And then that would be your
number. So that's that's certainly a pretty reliable way. It also depends upon having a book or
a magazine on hand. And it may or may not depend on kind of like, well, it definitely depends on
the frequency of certain words in a certain language, you know, obviously the letter t is probably
going to appear pretty frequently in your attempt at at pseudo randomness just because the letter t
in English at least is a, I think it may be one of the most common, common letters. It's a pretty
common one. I think, yeah, there are, I mean, there are stats online. You could find what, what letters
are going to pop up predictably. And then that might buy us your pseudo randomness. But again, random
enough. It does, however, like I say, assume that you have a book on hand. So I'm going to come back
to that concept because that that one sort of stuck with me. But some of the other efforts or
some of the other attempts that I made was something that I had found online called, well, it's
pretty common in it's it's a common basis for for encryption from what I understand. And I mean,
I think historically it was it was encryption like this was encryption. But now it's something more
just kind of used, you know, here and there within the encryption realm. I could be wrong about
this if you're if you're a professional with encryption kinds of credentials, then you can
certainly feel free to elucidate. But it's this it's this trick or it's a it's a math thing that you
do with the modulo. And the first the first the setup is that you have to choose two seed numbers.
And you can choose any really seed number that you want. But cramming this all into sort of the
the dice framework, we could say we need to choose let's say one through six. And so we'll we'll
assign our first seed X to two or second seed Y to three. And the number of sides of our on our
die to Z at six. So you're this is we're still in our setup mode here. So I have two and three is my
seed numbers and I have six as my side as my die my die side. So it's a D6 in the terminology of
people who know dice. So the first thing you do is you take two modulo six, which essentially is
two divided by six and six doesn't go in the two. So that's zero. And we say apparently that
you have two left over. So the modulo of two divided by six is or two mod two mod six is actually two,
which I did not know I thought it was zero. But apparently at least for the the for this exercise,
we say that the the if if it is zero, then we just give ourselves the originating number.
So three mod six is three. So that was basically pointless. But either way, that's our seed. So what
you do then this is no longer the setup. You have your seed numbers. So you do two plus three.
That's your your seed numbers and that equals five. So if we take five mod six, then we get a five.
So now we take the second seed number, why we always take why and we take our result that we just
got, which is five. So why most recently was three and then we add five and that produces an eight.
Well, there's something that six actually does go into. So eight mod six is two. So now we take our
previous why, which was five and we take our result, which was two and we say five plus two equals
seven. So seven mod six again, six does go into seven with one left over. So our result is one.
So now we take our previous why, which was two. We add one, our result. That's that gives us a three,
three mod six. We already know that one. That's three. Previous why is one plus three is our result
equals four. Four mod six is four. Previous why was three result was four equals seven. Seven
mod six is one. And you just keep going like that for as long as you want. And generally speaking,
it turns out to be random enough. I mean, that's not a very great sample that I just gave you,
but I don't think you really want me to just keep doing maths in your ear. So, but if we do take that
simple six six iteration sample, we've got five, two, one, three, four, one. It's pretty random.
And again, that's that's where we're limiting our range here to sort of a sick divisor of six.
So that that that's going to obviously limit the the randomness. But if if if you're trying to
emulate a dice roll, a typical D6 dice roll, that you have to admit that that looks like something
we would write down after six die rolls, five, two, one, three, four, one. You could totally you could
you could see that. And you could increase you could do a different number instead. Use a different
range. That's fine. So that was kind of an interesting exercise. And not a not a horrible way to
go really. It's in terms of of if you're sitting around needing random numbers in your head.
Then that's that's actually a really cool trick. And it's it's it's pretty fun. And you can just
keep going with it and just get you know, unexpectedly unexpected numbers every time. Unless you're a
math genius, where you do not think about that. And maybe it becomes predictable to you just because
you know you you think in in modulo anyway, which is fair. And that's another thing that I've
discovered about sort of obtaining random numbers. Your own worst enemy is your your own sort of
memory or level of knowledge. If if that math process right there that I just went through
causes you to kind of like actually think. Then it's probably random enough. If you think oh that's
so easy. Like and you could just rattle off the numbers instantly. Then you you may not think that
it's random enough because because there's no process there. There's you know you you see the numbers
and you just you know the result right away. And so it doesn't feel random anymore because you just
you know you can predict it essentially. So it kind of depends on your own your own ability to
do math really. So sort of more or less not really based on that but sort of based on that
inspired by that. I came up with this other method which is a a shifting table. And once again
like you can make it as as sort of big and complex as you want. I think it's dangerous. There's
a danger in this in the these exercises thinking that well a more complex and the bigger it is
the more random it'll be. And that falls apart really fast like trust me like you can think that
and next thing you know you're finding patterns in things that you just would have never thought
patterns could be found in. So I would say don't really get too fooled by by big inflated
numbers or bigger matrices you know it's it's not necessarily going to be any more satisfying
than a small simple one. So my shifting table idea and this may have been done before I don't know
all I know is that it came to me at some point and and I've been playing around with it. Again if
you're really into maths and and all this stuff you you probably know the technical names for all
of these things. The previous ones are pretty well known these the next two that I'm going to discuss
as far as I know are kind of my ideas. I mean I'm not saying they're great ideas I'm just saying
they're my ideas. So shifting table I have one row of one two three delta and then four five six.
So that's two rows sorry one two three delta and then on the next row four five six and that's
your matrix. So you have an uneven sort of table you have four columns on the top three columns
on the bottom and you move within that matrix you move north to south and then northeast south
northeast south northeast south. So in other words if we're counting on this table and none of
this will make sense yet just just bear with me. It's it'll be one four two five three six delta
and then we would wrap back around one four two five three six delta. So that's kind of the
progression. So you go down over down over down over down. The delta we can make we we can have
that mean anything or you can have it mean a shifting you know an alternating thing so that on your
first attempt delta means shift to the right on your second attempt delta means shift back to the
left on your third attempt delta could mean shift southwest whatever the empty the empty space
underneath the delta is you just skip that that just doesn't exist. So my idea was that if you
each if we choose a number probably a seed number would make sense first so let's just randomly
choose I guess a two. So we would enter the table onto one that would be one move and then we
would go down to four that's two moves and so our seed of two produced a four. So now what we do
is from the top of the table we count four spaces so one four two five so we're sitting on five
now that's our entry point and the reason we did that is because our results the result of our
of our previous go is our new seed number so we're at we're on space number four which is the
the number five in the sequence and and but well I guess before we would do that sorry we would
pick a number at random one through six so let's choose um well let's let's choose a
let's choose a three so we're sitting on five so then the next one would be three six and then we
land on delta and delta will just say shift us over to to the one which I don't really think would
make much sense because the empty space underneath the delta shifts us to the right anyway but
anyway we'll go with it for now so now we're sitting on one which is kind of an unfortunate place
to be because that means whatever number you choose next is going to be the number that you get
or does it so let's choose a let's choose a three again so we are at one and then four and then
two one two three so depending on how we're counting here I guess our our dice roll result would be
two um and then if we so now our new seed numbers two so we're back over on four and so then if
we choose I don't know six so then we go two five three six delta one two three four five delta
and then one so we're back over on one so it's I think that our sequence was something like four
one three six one or something like that um so it again there is some randomness there and usually
when I'm doing it I do it on paper and I just rewrite I shift the numbers manually so that I'm
always entering on the upper left quadrant uh and then counting down up down up down up and
and kind of do it that way but you don't have to you can just treat it as a map and then position
yourself on that map based on whatever your previous result was so your result becomes your seed
and your seed defines how much you shift the table over and all that does is confuse your brain
because then your brain as long as you don't you know as long as you don't think in numbers
which I know some people really can do that really well but as long as you don't it's just
enough obfuscation that you're sort of like oh I I I sense like a three would be a good choice
because that should get me in the upper range and then you you go to your table and you put yourself
where your seed number was and you're thinking oh darn I just chose I chose a three and I was on
five so then I go three six and then I land on that stupid delta number and that shifts me back
over you know to the left or something like that and you actually have rolled a three or or whatever
you want when I shift the the numbers I don't shift the position of the delta sometimes and
other times I do shift the position of the delta so that kind of throws some interesting randomness
into it so it's it's just one of those like it's just unpredictable enough so that your brain kind
of believes that there's randomness and I've had I've had pretty good success with that method
to be honest and I'm pretty happy with that the the shifting table method I'm happy enough with it
it's I'm sure it's very rudimentary and and it's you know I wouldn't I wouldn't base encryption
off of that method at all but it's something it it it does like I say it if you do it enough
which you know five iterations or whatever we just did isn't enough but if you do it enough you will
it does if you look at the numbers it feels like a dice roll and that that to me says random enough
the final method that I came up with is a pocket dice roller which is really dice it all
but I happened to attend a zine making workshop at at an art group that I that I attend locally
and the zine making workshop seems kind of silly I mean it's it's not exactly rocket science but
I figured I'd go because it was a good example or a good excuse rather to sit down and you
know produce a zine for you know analog fun for an hour for free and then you end up with a zine at the
end which of course I've since thrown out but it was a good exercise but not not not for the reason
that I kind of had anticipated the the the the the way that the facilitator the instructor guy was
doing the zine was like this sort of self folding pocketbook from one sheet of paper
that never seen this before I have since found out that it I don't know who came up with the idea
first or or whatever but but if you go to a site called pocket mod I think dot com they I don't
know if again I don't know if they like invented this or if they're just the ones who
who came up with the brand pocket mod but their their site certainly comes across like it was like
their own brilliant idea again I have no idea if that's correct like this could have been
something that dates back to the 1600s for all I know I have no clue so I hesitate to call it a
pocket mod but but if you're doing searches online for for for this this thing it's pocket mod dot
com POC K E T M O D dot com so anyway the point is that you get to take this letter size or A
four size paper you fold it in half and then you fold that in half then that I'm talking
so that you have long strips of paper so you've got these four sort of panels and then you
fold that in half so now you've got eight eight squares and then you take the the two middle
long panels together and cut down the center so you've got these weird sort of flaps and you fold
the flaps you fold the top flap to the left bottom flap to the right or vice versa and then fold
that in half and then fold that in half trust me it makes more sense if you see it I've got
instructions online and pocket mod dot com also has instructions the the end result is that you
have a a little booklet that you can fit into your pocket it's about the size of I say I would
say a poker card a playing card whatever or business is it that's because it's bigger than a
business card but you know it's it's it's basically that yeah it's a bit taller than a business
card a little bit wider but yeah you know so it's it's a little tiny booklet of eight pages
it's a little bit funky because um page one and three oh and two all all pages all pages are
are sort of like they're they're folded over on each other you know so that there's there there
are probably refinements that could be made to this um you know you could you could cut some more
edges to produce more pages I just don't know how that would affect it looks like you could at least
cut page one um yeah so it's a little bit funky but I mean it's honestly it's really handy it's
like this self-contained little booklet of at least eight pages and um it's it's quite nice
and this idea kind of started me thinking that maybe there was a way to produce a random number
generator uh that could be printed on a little uh pocket notepad booklet pocket mod I guess
is what we'll call it um and and that could be like an easy sort of portable way to um to to
have a random number generator and so I um I went and described us and laid out this uh four up
or eight up um little design um of of some matrixes matrices and there are four matrices per page
two of them are facing upwards two of them are upside down so essentially we've got sixteen
pages if you will since so each page is basically dual purpose so you can flip the book over
or over again or over and you you'll you'll always have a matrix facing up um
meaning that you uh you know you you look at the matrix that's that's correctly oriented for you
and if you don't like that matrix then you can flip the book over and you got a new matrix to look at
so no matter where you turn no matter which way you turn the book you have a matrix to to look at
now the way that it works is um similar to all these other methods really it's you you have to
first come up with a seed so um the the first what we'll just use the the six the d6 matrix
to begin with although I do have a d a d 10 matrix as well on on the same booklet so if you choose
any letter from from a to f then uh let's just choose let's say d delta uh so we look at the first
page and again you can flip if you you know you it's a flippable book so you've got like four
different possibilities just to start with um so I'm kind of turning it over in my hand and here I've
got um actually it's the way I designed it looks like you only have three possibilities for delta
but that's just because that's that's just the look of a draw um anyway um so here's a delta and it
says delta gets a three so three is my seed number and that means that on my next on my on my next
role as it were uh I need to go to page three so I'll just I'll I'll use the front cover as one
next page is two next pages three and then before I look at that uh I should choose numbers
or a letter rather a through f so we'll choose uh the beta I'll open it to page three and I get
another number three so that's the same number as what I just had so rather than using the same
page I'll flip the book over I'll choose a letter uh let's go with a and I'll go to page three my new
page three um a gets a four so then I will choose another letter um let's do delta again and I'll
turn to page four and now that got a six and then if I do if I'll go to page six but before I look I
will choose another letter let's go with C because we haven't done that yet another six um I'll flip
the book go to page my new page six I'll choose a number letter rather let's go with B beta again uh
that's a one and and so then I would go to the page one so so you just can't keep doing that like you
your result again is your is the seed for your next go and you are choosing letters that um
that get assigned a different number depending on what page you happen to have to turn to
there are enough matrices in here that uh it's quite unpredictable um as to as to what you're
going to be rolling not only because it's difficult to remember what each matrix you know the
configuration of each matrix because there are 16 of them um but also because you can well there are
eight let's say and you can flip the book so then there are eight more so there are 16 um so the
page numbers there are no page numbers so you just you kind of count on your own and depending on
the orientation that page number may or may not be you know strictly speaking is that page two or
is it page six you'll never know um and and the the letters I think I've I've found really help
because that way you're not really thinking of numbers you're thinking of letters and I mean yes
it's a thin veil you can kind of think well f is six okay that's easy so I'll just choose f but
I mean that's going to screw you over because I just turned to um page one two three four five f is two
so you know there's there's there's some unpredictability there and it it has ended up being
uh random enough for sure um and I've published that particular
system on GitLab so if you go to GitLab.com slash not class two slash pocket dice roller
then you will see um the the system itself both the um scribus source code or source code
source document uh as well as the um distributable a four and letter size sheets of paper that you
can print and and redistribute and and create yourself and there there are instructions on the
back of the of the pdf or you know if you print it out dual side the back of it is instructions
on how to fold it and where to cut um and also how to use it just in case you need a or a reminder
and then like I say there's a there's a d ten matrix in there as well so you can choose from a to j
and then that that doesn't exactly work I mean it does there are only eight pages in the book
so you just you can count matrices or you can just kind of cycle back through you know kind of
flip it and recycle go back through the pages if you get something like a nine or a ten uh doesn't
really matter and of course since you have a d six and a d ten you also inherit not strictly speaking
but again random enough speaking you kind of inherit a d 12 and a d 20 so you know if I mean if we're
assuming that two rolls of a d six equals the d 12 which statistically I'm pretty sure it does
not but again random enough good enough it tends to work out so that's my pocket dice roller system
which you're you're welcome to to beta test for me um it's it's published on getlab.com as well as
rpg rpg now dot com rpg now dot com just look for pocket dice roller I guess and that's it it's a
simple little system it it it's pretty reliable it's random enough hopefully this episode's been
interesting um and if nothing else random you've been listening to hecka public radio at hecka
public radio dot org we are a community podcast network that releases shows every weekday
Monday through Friday today's show like all our shows was contributed by an hbr listener like
yourself if you ever thought of recording a podcast then click on our contributing to find out
how easy it really is hecka public radio was founded by the digital dog pound and the infonomican
computer club and it's part of the binary revolution at bnw.com if you have comments on today's show
please email the host directly leave a comment on the website or record a follow-up episode yourself
unless otherwise stated today's show is released under creative comments attribution share
three dot org license