[EROFT week 10] Creating randomness

Meditation #5 assigned

First, produce your own implementation of digital randomness, without using any pre-existing implementation (e.g., you can’t use the random() or noise() functions in p5.js). Consider mathematical solutions and physical solutions. Aim for a generator that produces randomness with a uniform distribution.

Second, incorporate an alternative random number generator into one of your existing projects. You can either use the generator you implemented for step one or a generator that produces random numbers with a distribution other than uniform. Be curious and creative!

 

I created a very simple randomness using the internal clock of the sketch. That was:

var ran;
var seed;
var i = 1;
function myRandom() {
seed = int(millis().toString().slice(-3));
ran = seed % 100 / 0.01;
}
return ran;
}

For some reason, it was working really slowly, but the implementation made this pattern, which looked pretty good for me.

Captura de Tela 2019-04-15 às 00.01.11

Next day I opened the same sketch, which was running faster, but it made both patterns below in different runs:

I was really confused about this. I actually still am. My guess is that my internet connection was configured differently in both days, and in my console I could see that it would register the same millis() for many frames in a row, making the stripes that we can see in the patterns.

As soon as I saw the patterns in the second day, I realized that my math function was not very smart, since the % operator would just give me the last digits of the millis(), so it was just going in a sequence, even though I couldn’t tell that from the numbers I was getting in the first day. Here’s a sample of the first day’s myRandom():

0.32
0.97
0.24
0.98
0.08
0.42
0.55
0.05
0.61
0.28
0.99
0.56

With that, I was trying to add a new variable that would change independently. I wasn’t exactly successful in making an uniform distribution with this, but I got some interesting results.

var ran;
var seed;
var i = 1;

function myRandom() {
seed = int((millis()+i).toString().slice(-1) + millis().toString().slice(-2,-1));
ran = seed / 100;

i++;

if (i > 5000) {
i = 0;
}

return ran;
}

eroft w10.PNG

var ran;
var seed;
var i = 1;

function myRandom() {
seed = int((millis()+i*2).toString().slice(-1) + (millis()*2).toString().slice(-2,-1));

ran = seed / 100;

print(millis(),seed, ran, i);

i++;

if (i > 100) {
i = 0;
}

return ran;
}

eroft w10 2.PNG

I implemented this last version into Oracle Landscapes, and I didn’t notice any changes except for being a little slower. Here’s the link for myRandom(), and the Oracle Landscape with the implementation.

Deixe um comentário

Preencha os seus dados abaixo ou clique em um ícone para log in:

Logo do WordPress.com

Você está comentando utilizando sua conta WordPress.com. Sair /  Alterar )

Imagem do Twitter

Você está comentando utilizando sua conta Twitter. Sair /  Alterar )

Foto do Facebook

Você está comentando utilizando sua conta Facebook. Sair /  Alterar )

Conectando a %s