Kassen wrote:
...What we also can't have is random melodies to play sounds that are using this technique, at least not unless we implement our own random number generator as a public class. Sadly we can't have our cake and put it in the blender, at least not at the same time.
Sure we can.
It's not always terribly easy to implement a pseudo-random number
generator, but it is straightforward, and often they are very well
documented. Consider the very simple Xorshift RNGs:
// xorshift random number generators
// see
// Marsaglia, G. "Xorshift RNGs", Journal of Statistical Software,
Vol. 8, Issue 14, Jul 2003.
// http://www.jstatsoft.org/v08/i14
class rng
{
int seed;
2147483647.0 => float MAX_VALUE;
fun int nextInt()
{
return 0;
}
fun float nextFloat()
{
return 0.0;
}
fun float nextFloat(float n)
{
return 0.0;
}
}
class xorshift extends rng
{
fun int nextInt()
{
return seed;
}
fun float nextFloat()
{
return (nextInt()/MAX_VALUE);
}
fun float nextFloat(float n)
{
return (n * nextFloat());
}
}
class xorshift13_17_5 extends xorshift
{
fun int nextInt()
{
(seed << 13) ^=> seed;
(seed >> 17) ^=> seed;
(seed << 5) ^=> seed;
return seed;
}
}
xorshift13_17_5 xor;
2463534242 => xor.seed;
// not sure if these are working correctly, since chuck uses an unsigned integer
while(true)
{
1::second => now;
//<<