A pseudorandom number generator - when algorithms roll the dice

Greetings to you all, this is a crazy artist from the land of a thousand (frozen, at this time of the year) lakes, doing an art installation with the Arduino (Uno).

Here is a picture of my art installation. This is a work in progress.

And the installation will look something like this:

See the random generator in action.

I will post more pictures of the finished installation, once it is up in the gallery. Now I am still tinkering with it.

The Arduino code was a piece of cake. I did a horrible mess at first using switch case to convert decimal numbers to binary. Now I used the PORTD command and the code is a lot prittier. Here it is on github.

Unlike in the video, now I get a fast sequence of random numbers followed by a random number for q seconds. Just tweaking this is a lot of fun.

I will add interactive elements in my next project. I have a lot of ideas and the Arduino is simple to program so it does not inhibit creativity, it makes it possible to do absolutely anything!

If there are any cryptographers out there - please comment as to how random this is :wink: Because I have zero idea...

As for the electronics, it is very easy. You need a seven segment LED, and a BCD -> 7-segment decoder. The Arduino digital outputs are connected to the decoder, which is connected to the LED. As to how you connect them, read the datasheets of your parts. This is not a follow along tutorial, but if you have any question, I will try to help you out. Another solution would be to just connect the LED directly to seven digital outputs on the Arduino, but I happened to have the right part in my box, so using the decoder was simpler.

Here is what I used:

LED:

Kingbright SA08-11SRWA

BCD-7-seg decoder:

SN74LS247N

Thank you all and if you just post what you think that'll make me very happy.

ozf1r

1 Like

next time my boss say to me "your table is a mess" i will say "it is interactive art".

7 Likes

As you know, it's "pseudo-random". If you know the algorithm it uses, and you know the the seed value it has been given, it is 100% predictable.

But even if you know the algorithm, without knowing that seed value, it appears very random and extremely difficult to predict.

Each seed value results in a sequence which will be the same every time. If you start with a seed value chosen randomly from a list of 10 seed values, you will always see one of 10 sequences.

Your code sets the seed like this

  // Let's make it truly random!
  randomSeed(analogRead(0));

So an important question is, how many possible seed values will that give us? In theory, it could be up to 1024 different seed values because analogRead() can give a result between 0 and 1023. But in practice, how many different seed values do we actually get? You could write a small sketch to find out.

But it will only work on Uno and other types of Arduino based on the same chip, such as Nano 3, Pro Mini and some others. But with Arduino based on other chips, it will not work, and may not even compile.

There are ways to write the code which will work on all types of Arduino.

1 Like

Thanks! I plan not to use this for cryptography, so for an art gallery display the randomness is good enough. For added randomness however, I did add a voltage divider just now made of two LDR resistors, so the analog value should be a bit more random, unless the light is exactly the same... Trying it out and trying not to move and cause any shadow when resetting the board I get a different value every time the board boots up, so this is enough of cryptography for me :wink:

1 Like

Good to know. The code is very short and anyone wanting to do this on other boards can tweak the code as much as they want, so I don't see a huge problem with this code not being portable.

Thanks though for looking at my code! I am an artist, not a geek.

Not if they are with another microcontroller. I avoid working directly with registries whenever possible for this very reason. In your case, a BCD decoder is not even needed. I prefer to do things in software rather than hardware as then you can even display hexadecimal characters just by changing the program.

I wrote:

"Another solution would be to just connect the LED directly to seven digital outputs on the Arduino, but I happened to have the right part in my box, so using the decoder was simpler"

I shall not argue about it :wink:

There was something else.

No current limiting resistors. There should be one for each segment.

Without these, too much current could flow which will damage and cause the chip or the display to fail after some time.

How much time? Hard to say. Perhaps that's part of the art? It could fail just before it gets sold at Sotheby’s for £18M.

No resistors to make self-destructing art? Sounds like the Kramer portrait fiasco.

It's a cool project, OP. Good job figuring most out on your own!

There are current limiting resistors now - thank you for very valuable information! Now it will not selfdestruct...

Made me think of this:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.