soul-lang / SOUL

The SOUL programming language and API
Other
1.71k stars 95 forks source link

Rand #51

Closed joekingTheThird3 closed 3 years ago

joekingTheThird3 commented 3 years ago

Can I have it please? rand(). If we have rand then we need srand() - srand (time(NULL)); Thank you.

julianstorer commented 3 years ago

https://soul-lang.github.io/SOUL/docs/soul_library.html#mod_soul_random

P.S. please don't be someone who encourages the use of rand() or srand(), even in C code! It's an ancient, poorly-designed function and would have disappeared years ago if it wasn't for legacy support in the C library. There are far better alternatives in every language now.

joekingTheThird3 commented 3 years ago

Thanks. I am getting lost in the documentation. Didn't see it there. Random repeats after a cycle or with the same seed. I wonder if sound of a long cycle of notes is actually easier to deduce than a visual rendering of a cycle of integers. I am not very familiar with C++. I know in js

  var array = new Uint32Array(1);
window.crypto.getRandomValues(array);

is more secure.

julianstorer commented 3 years ago

Sorry, but I don't really understand your question... Obviously any pseudo-random RNG will repeat eventually, but this one will take billions of iterations to do so.

Like the docs very clearly say, this isn't in any way intended to be a secure crypto-level RNG, it's a simple, fast one that's designed for audio purposes. If you need something secure, then you'd need to write that yourself.