Can we have a random number generator?


@codinghorror, I was wondering if there was a way to implement a random number generator in the comments? It would suddenly make it possible to play certain BBS games. Hell, we could execute a full on D&D game with such a feature. It could be as simple in syntax as


or even simpler,


(To indicate two die.)

Is this possible?

ETA: To be clear, the input would look as above, but the output would just be a number, maybe with a custom format to indicate that it was generated by the generator, but not typed by the user.

Did you ever want to play questions?

I like this idea!

I have a little app (Feudz™ Dice Roller) on my iPod (possibly available for Android OS also) that uses a fairly simple syntax to allow quite a lot of customization for results:

[number of dice]d[number of sides]


  • 1d6 would be a typical, cubic die.
  • 2d8 would be two 8 sided dice
  • 3d12 would be three 12 sided dice
    and so on.

A “die” is always presumed to generate an unweighted random number between 1 and the number of sides it has, do d7 would generate a random number between 1 and 7 inclusive with equal probability of each result.

The syntax is enhanced by chaining with modifiers using + or -

  • 1d6+2 would generate a number between 3 and 8
  • 2d6+5 would generate a number between 7 and 17, with a central tendency toward a result of 12 (because the two dice are rolled independently)
  • 14d3+11 would generate a number between 25 and 53 with a very strong central tendency toward a result of 39.

Results can be further chained like so:

  • 2d6-1d7 which would generate a number between -5 and 19 with a central tendency (albeit a weak one) toward a result of 3.


Thirty seven!

Random enough?


[mandatory link to XKCD comic on random-number-generators redacted]


@codinghorror - Asking for a turing-complete markup language is not too much to ask for!

@sam - Stop doing whip-its in the Discourse lounge, and hop to it!


I imagined it was always part of @doctorow’s plan to help turn BoingBoing into a general purpose computer.


This is fun!



What about writing a script to link to a random post in the Count To Ten-Thousand thread?




a mechanical ***k?


Just look at it.


44 (forty-four)




There’s no 406 on bingo cards. What is wrong with you?!


That’s weird. Mine does:

Here’s another fun one we can all play!


That Bingo board looks like it’s from Malkovich’s head.


I think it would be complex to implement this in a way that was hard for the user to game.

You’d need to mark any edits to the post directly, as well as make it clear whether a user had simply deleted their original post and just re-written another one. I think that this would make a complex request.

One simple solution I guess is simply to make all those posts uneditable and undeleteable. But again this requires more changes than simply a macro.

Another, non-technical (and probably impracticable) solution would be to copy the way the old street lotteries (numbers rackets) used to work. A player could pick a stock index, and then the next day that would result in whatever the cent value of that stock closed at. So if in my post yesterday I picked “APPL”, that would result in a value today of “7” (closing price was 132.17).

It’s pretty ungainly, but I kind of like the time-delayed nature of it :wink:


The solution to this problem is fairly simple, you just need a pseudo random number generator, that uses the original post creation time as seed:

That’s my implementation of a javascript module that does something similar, adding a syntax for dice would be trivial.

Using a PRNG you don’t need to lock a player’s edits.

The main characteristic of this implementation of a pseudo random number generator ( PRNG ) is that numbers are pregenerated in an array using a seed.

If you use the same seed, you’ll get the same sequence of numbers every time.

From the top of my head, that has another two use cases:

Say you are playing Endless Sea (or another roguelike), and a player tries to cheat the random number generator saving just before a skill check (or closing the program), to reload the game until it’s possible to pass a check with a 1% chance of happening.

Using a PRNG you can prevent that, because after every load, the PRNG will give you the same number sequence. That is, unless the player decides to take another action that causes a PRNG number to be provided before the check, and even then, it mitigates the effect of that kind of cheat, because the player does not know how many times he has to cause a check before it is possible to succeed on the check he wants.

The other use case, is to make the seed transparent to the player, in order to allow them to share it:

That is used in Dwarf Fortress to share pregenerated worlds, and in The Binding of Isaach Rebirth, allowing players to share a procedurally generated dungeon with other players. (Say you want to play the same map that Northernlion is playing on youtube).

PS: If you use the same seeds I provide on Usage you’ll get the same numbers I did.