Linear Feedback Shift Registers For FPGAs

If you want to start an argument at a Hackaday meeting, you have only to ask something like “How much does this weigh?” or “What time is it?” But if you really want to start a street brawl, you can always say, “Are these numbers random?” Making random numbers that are actually random is actually a tough nut to crack. Most of what we do is, technically, pseudo-random (but we’ll say random number and assume you know what we mean). One way to generate seemingly random sequences is to use a linear feedback shift register or LFSR. You can use LFSRs in software, but they are also very useful in hardware design and [Adam Taylor] takes us through his use of them on FPGAs in a recent post. Continue reading “Linear Feedback Shift Registers For FPGAs”

Yes We Have Random Bananas

If you ask a normal person to pick a random number, they’ll usually just blurt out a number. But if you ask a math-savvy person for a random number, you’ll probably get a lecture about how hard it is to pick a truly random number. But if you ask [Valerio Nappi], you might just get a banana.

His post, which is in two parts, details how what computers generate are actually pseudo-random numbers. You can easily make sure that every number has the same probability of selection as any other number. The problem is that you have to start with something — usually called a seed. For the purposes of playing games, for example, you can grab some source of entropy like how many microseconds since a hardware timer last rolled over, the number of input pulses you’ve received from a mouse lately, or how long you had to wait for the enter key to depress after asking the user to press it. But if you know that seed and the algorithm you can perfectly predict what number the computer will generate next so it isn’t truly random.

Continue reading “Yes We Have Random Bananas”

Electronic Dice Is Introduction To Microcontroller Programming

By now most of us are familiar with the Arduino platform. It’s an inexpensive and fairly easy way into the world of microcontrollers. For plenty of projects, there’s no need to go beyond that unless you have a desire to learn more of the inner workings of microcontrollers in general. [Cristiano] was interested in expanding some of his knowledge, so he decided to build this electronic dice using a PIC microcontroller instead of the Arduino platform he was more familiar with.

As a result, this project is set up as a how-to for others looking to dive further into the world of microcontrollers that don’t have the same hand-holding setup as the Arduino. To take care of the need for a random number for the dice, the PIC’s random number generator is used but with the added randomness of a seed from an internal timer. The timer is started when a mercury tilt switch signals the device that it has been rolled over, and after some computation a single digit number is displayed on a seven-segment display.

While it might seem simple on the surface, the project comes with an in-depth guide on programming the PIC family of microcontrollers, and has a polish not normally seen on beginner projects, including the use of the mercury tilt switch which gives it a retro vibe. For some other tips on how to build projects like this, take a look at this guide on how to build power supplies for your projects as well.

Continue reading “Electronic Dice Is Introduction To Microcontroller Programming”

555 Timer On Its Own In Electronic Dice

One of the most common clichés around here is that a piece of equipment chosen for a project is always too advanced. If a Raspberry Pi was used, someone will say they should have used an Arduino. If they use an Arduino, it should have been an ATtiny. And of course, if an ATtiny was used, there should have simply been a 555 timer. This time, however, [Tim] decided to actually show how this can be done by removing some of the integrated circuits from an electronic dice and relying entirely on the 555 timer for his build.

The electronic dice that [Tim] has on hand makes use of two main ICs: a NE555 and a CD4017 which is a decade counter/divider used for cycling through states. In order to bring the 555 to the forefront of this build, he scraps the CD4017 and adds an array of 555 timers. These are used to generate the clock signals necessary for this build but can also be arranged to form logic circuits. This comes at a great cost, however. The 555 chips take up an unnecessarily large area on the PCB (even though these are small surface-mount chips), consume an incredible amount of power, and are very slow. That’s fine for an electronic dice-rolling machine like this one, but that’s probably where [Tim] will leave this idea.

The 555 timer is a surprisingly versatile chip, and this project shows that there is some element of truth to the folks claiming that projects need naught but a few 555s. We’ve seen entire CPUs built using nothing but 555s, and even a classic project that uses a 555 timer to balance a robot.

Linux Fu: The Linux Shuffle

Computers are known to be precise and — usually — repeatable. That’s why it is so hard to get something that seems random out of them. Yet random things are great for games, encryption, and multimedia. Who wants the same order of a playlist or slide show every time?

It is very hard to get truly random numbers, but for a lot of cases, it isn’t that important. Even better, if you programming or using a scripting language, there are lots of things that you can use to get some degree of randomness that is sufficient for many purposes. Continue reading “Linux Fu: The Linux Shuffle”

Random Numbers From Outer Space

Need a random number? Sure, you could just roll a die, but if you do, you might invite laughter from nearby quantum enthusiasts. If it’s truly, unpredictably random numbers you need, look no farther than the background radiation constantly bombarding us from the safety of its celestial hideout.

In a rare but much appreciated break from the Nixie tube norm of clock making, [Alpha-Phoenix] has designed a muon-powered random number generator around that warm, vintage glow. Muons are subatomic particles that are like electrons, but much heavier, and are created when pions enter the atmosphere and undergo radioactive decay. The Geiger-Müller tube, mainstay of Geiger counters the world over, detects these incoming muons and uses them to generate the number.

Inside the box, a 555 in astable mode drives a decade counter, which outputs the numbers 0-9 sequentially on the Nixie via beefy transistors. While the G-M tube waits for muons, the numbers just cycle through repeatedly, looking pretty. When a muon hits the tube, a second 555 tells the decade counter to stop immediately. Bingo, you have your random number! The only trouble we can see with this method is that if you need a number right away, you might have to go get a banana and wave it near the G-M tube.

Whether this all makes sense or not, you should check out [Alpha-Phoenix]’s project video, which is as entertaining as it is informative. He’s planning a follow-up video focused on the randomness of the G-M tube, so look out for that.

Looking for a cheaper way to catch your random numbers? You can do it with a fish tank, some air pumps, and a sprinkle of OpenCV.

Continue reading “Random Numbers From Outer Space”

How Random Is Random?

Many languages feature a random number generator library for help with tasks like rolling a die or flipping a coin. Why, you may ask, is this necessary when humans are perfectly capable of randomly coming up with values?

[ex-punctis] was curious about the same quandary and decided to code up an experiment to test the true randomness of human. A script guesses the user’s next input from two choices, keeping a tally in the JavaScript backend that holds on to the past five choices. If the script guesses correctly, they take $1 from the user. Otherwise, the user earns $1.05.

The data from gathered from running the script with 200 pseudo-random inputs 100,000 times resulted in a distribution of correct guess approximately normal (µ=50% and σ=3.5%). The probability of the script correctly guessing the user’s input is >57% from calculating µ+2σ. The result? Humans aren’t so good at being random after all.

It’s almost intuitive why this happens. Finger presses tend to repeat certain patterns. The script already has a database of all possible combinations of five presses, with a counter for each combination. Every time a key is pressed, the latest five presses is updated and the counter increases for whichever combination of five presses this falls under. Based on this data, the script is able to make a prediction about the user’s next press.

In a follow-up statistic analysis, [ex-punctis] notes that with more key presses, the accuracy of the script tended to increase, with the exception of 1000+ key presses. The latter was thought to be due to the use of a psuedo random number generator to achieve such high levels of engagement with the script.

Some additional tests were done to see if holding shorter or longer sequences in memory would account for more accurate predictions. While shorter sequences should theoretically work, the risk of players keeping a tally of their own presses made it more likely for the longer sequences to reduce bias.

There’s a lot of literature on behavioral models and framing effects for similar games if you’re interested in implementing your own experiments and tricking your friends into giving you some cash.