Question #2: Verifiably Random Numbers

We want to generate some random numbers. For simplicity, we'll assume we want a random number between 1 and 100. We want our random-number generator to be:

  • Public (everyone knows the same random numbers, at roughly the same time)
  • Fair (every number has the same odds of coming up)
  • Trustable (everyone knows it's fair--it should be above doubt)
  • Fast (we want to generate as many numbers as possible, as often as possible)
  • Unpredictable (you shouldn't be able to guess the result before it's revealed)

Some security experts suggest that a trustable system should also be:

  • Decentralized (no single person, organization, or computer picking the numbers). This is because a central trusted group requires faith in that group and its security.

One for this in the real world was the "Numbers Game", a popular illegal lottery in the 1800s, in the USA. The winning numbers were selected at random each day, like most lotteries--by the mob. After complaints about rigged lotteries, the winning numbers started to be picked more transparently. For example, it might be the closing price of the New York Stock Exchange--just the cents value. For a hundred dollar lottery, you would be crazy to worry about someone messing with the New York Stock Exchange. (But if it became a billion- or trillion-dollar lottery, you should worry again.)

The biggest problem with using a stock exchange that it's slow. You only get one set of numbers a day.

Can you come up with a better random-number generator?

Tagged

Whiteboard Calendar

Using electrical tape, I split a whiteboard into sections. Voila, whiteboard calendar.

A teacher friend of mine already knew exactly how to do this--apparently it's common knowledge among teachers.

I did look if there were either large, disposable calendars (no) or existing whiteboard calendars (they're laminated posters that don't actually erase). A 3ft x 2ft (1m x 0.6m) whiteboard costs $30, and you can get electrical tape for $1.

The stickers look bad--I half-assed them. I need tons of big stickers or none at all. This was way too tentative. I do want some kind of decoration, though.

Tagged ,

Hack-a-Day 2024

In 2022, 2023, and 2024, I did "Hack-a-Day", a challenge to myself to do one project a day for all of November. It's vaguely modelled off NaNoWriMo, a challenge to write a book in November.

This year, I completed 21 projects in 30 days. On average, I worked 7.5 hours per project. My expenses for the month were $130, divided over only three projects--ingredients for Project L.E.M.B.A.S. ($85), aluminium to mill for soma cubes ($28), and missing parts for my TODO whiteboard ($19).

 a calendar listing projects from 2024

To see a list of all projects from this year and previous ones, check out my hack-a-day website.

Tagged

Hack-a-Day, Day 30: LED Fireplace

Having prepped my ESP-32, I decided to make an LED fireplace today.

The plan was to put an LED strip on a piece of cardboard, and have slowly shifting red, orange, and yellow lights going up and down, somewhat like a music visualizer. I knew the bare LEDs wouldn't look good, so the plan was to put the cardboard somewhat deep into the fireplace, and add some translucent tissue paper layers in front to diffuse the lights.

 vertical 'strips' of lights
vertical 'strips' of lights

Sadly, of my three ESP-32s, two were broken. I ended up instead using an ESP-8266, since I had several laying around. Annoyingly, the boards I have are so wide it's impossible to breadboard the, so I used perfboard instead.

Having carefully set up the circuit, I flipped the on switch and... nothing happened. It was about 10pm at this point, and I was starting to run out of energy, so I gave up.

Very late that night, I found the problem was the resistor I added--the LED strip has a built-in resistor as well, and apparently the two together were too much. I eventually got the lights to turn on, but too late to finish the project for the day.

 my test pattern looks a little christmas-y
my test pattern looks a little christmas-y
Tagged , , ,

Hack-a-Day, Day 29: ESP32 Microcontroller Documentation

A while back, I was trying to set up a power monitoring system, and I mistakenly bought the wrong ESP dev board. The ones I ended up are sold by some fake-named Chinese manufacturer. They seem pretty fine, much like any other ESP32 dev board, but they have an unusual 30-pin layout.

I tried to add some electronics to my whiteboard hack earlier this month, but got frustrated pretty quickly, failing to program the microcontroller, and with no idea what the pinout was.

Today I decided to take it slower. I'd figure out how to program it, and understand the pins. If I had any time left over, I'd do a project.

First, I got flashing the chip to work. It turns out my main problem from the first time was a bad upload serial rate. I debugged the problem with the help of friendly folks on IRC. Espressif (the ESP32 manufacturer) has helpful troubleshooting instructions, which suggest using the python serial terminal, miniterm. By taking a step at a time, I got the microcontroller working.

Next, I installed and set up platformio, which I had never used before. My experience was that it was pretty good once set up, but a little hard to get started on the command line. Still, I'm happy, and will probably use it again. Platformio has two options--the popular Arduino framework libraries, or the Espressif-provided esp-idf libraries. Based on the small code samples I found, I'll most likely use the Arduino libraries, but some specialty features are just not available on Arduino.

Finally, I set up platformio one last time, with the VS-Code based PlatformIO IDE. Again my experience was pretty good. Sadly, the open-source VS-Code does not show the same set of extensions, and I had to use the binary version. (Aside: Come on, vs-code. Don't call your package and program code. That's a dick move.)

The writeup of how to get your dev environment set up is on github.

Finally, I made the below pinout diagram with the rest of my night.

 the colors looked better when it was bigger, I swear
the colors looked better when it was bigger, I swear

Happy hacking!

Tagged , ,

Hack-a-Day, Day 27: Minecraft Mod

Today I made a minecraft mod, using Fabric. Modding sure has changed a lot since I last tried it in Forge, maybe ten years ago! Java's changed a little too, even.

My mod adds a dirt slab, that's it. I didn't really have time to get past the basics, but I think the occasional hack that's just a learning experience is okay.

Code and mod download are both on github this time.

Fabric is well-documented and friendly. The main downside is that there's no "abstraction later" between Minecraft and the mod. This means your mod will work with exactly one minecraft version on release. Additionally, when a new version of minecraft is released, you need to update and re-release your mod (and there are usually actual changes to be made).

Tutorials used:

Tagged ,

Hack-A-Day, Day 26: No Room for Error

I made a coding challenge, vaguely tied up as a game. Your goal is to complete simple coding challenges, with a major twist--you only get one try. You can only hit RUN once. (Well, actually you can hit RUN more than once. But it gets marked as failed.)

 the game is called "No Room For Error"
the game is called "No Room For Error"

It put together about 10 challenges, together with some story narration.

The game problems are now tested.

You can play online. The code is on github

Tagged , ,

Hack-a-Day, Day 25: Go Screensaver

Today I made a Go "screensaver".

  go game in progress
go game in progress

You can see it online here. The source code is on github.

Games are taken from OGS, and played real-time. Provided are a selection of 1000 random games from OGS, a popular Go server. Games play in real time, the same as when they were originally played.

I made this to have a screensaver for my mantel.

 go games play above my fireplace
go games play above my fireplace

Hope you enjoy.

Tagged , ,

Power Beeps

One feature I really liked about older ThinkPad models was that when you plugged in power, it would give a little chirpy beep. Same when you disconnected it.

The downside to system beeping is that it gets really annoying. I don't want a failed tab completion to go "beep" aloud, especially when I'm in public.

I aggressively turn off all kinds of system bells, etc. Sadly, I get no beeps either.

Today I wrote a little python script to monitor power beep how I want. It plays it through my computer speakers (unmuting them if needed, just long enough to beep). It works for me on both ALSA and pulseaudio with an ALSA bridge (I have a few computers on each).

My default settings are:

  • Two falling tones when power is unplugged
  • Two rising tones when power is plugged back in
  • Two warning beeps when the lowest battery reaches 10% (my laptop has two)
  • Three warning beeps when the lowest battery reaches 5%.

Source code is on github if you want to use it too. To change the thresholds or beeps, you'd have to change the code. No fancy configs, sorry!

Tagged

Hack-a-Day, Day 23: Unfinished Game

Today I wrote a game called Little Herbalist. Or at least, I started to.

 part of "little herbalist"
part of "little herbalist"

I'm pretty pleased with what I have--random ingredients appearing in various colors, which you can add to a brewing potion. The potion changes colors based on what ingredients you've added.

It's definitely not a complete game, and I'd like to work on it again another day.

You can play the unfinished game online or read the source code on github.

Tagged ,