LingDong- / q5xjs

A small and fast alternative (experimental) implementation of p5.js
https://q5xjs.netlify.app/
The Unlicense
549 stars 25 forks source link

random isn't random #2

Closed oori closed 4 years ago

oori commented 4 years ago

Go to examples --> random III: q5 returns same value "apple", not random. p5 is random. same for the other random examples (I + II), they always render the same "not" random graphics.

I browsed through your code to see where this originated from, but didn't see anything, so I guess p5.random is missing. (btw: make_site.js is a superb hack!).

LingDong- commented 4 years ago

Hi @oori,

Thanks for reporting the issue. This is related to the random seed: calling random() multiple times in a row, or calling randomSeed() first will produce actually random values.

q5.js does randomize the seed at start up, but the randomized range was too small so the first call to random() end up yielding somewhat similar values, and in the case of selecting an item from list of 4, it gets rounded to the same index.

This is now fixed: the seed is now selected from 0 to RAND_MAX at start up, so even the first call to random() gives good random result. 5c48cdb6ae12810b3c812f19396051e13c1d82ba

Thanks!