On Thu, 28 Jan 2010, cal wrote:
Gabriel M. Beddingfield wrote:
[ ... ]
srandom_r(salt, &seed);
Thus, if you repeat the note with identical velocity... you'll always
get the same random-number sequence.
or do you just get a segfault :-) ?
Wow. random_r() is /really/ poorly documented.
Non-segfaulting example attached.
-gabriel
#include <cstdlib>
#include <iostream>
using namespace std;
int main(void)
{
unsigned short int note, velocity;
int32_t salt;
struct random_data seed;
char rand_state[256];
note = 63;
velocity = 120;
salt = ((velocity & 0x7F) << 7) | (note & 0x7F);
// See http://lists.debian.org/debian-glibc/2006/01/msg00037.html
seed.state = (int32_t*)rand_state;
initstate_r(salt, rand_state, sizeof(rand_state), &seed);
int32_t res;
for(int k=0 ; k<20 ; ++k) {
random_r(&seed, &res);
cout << res << endl;
}
return 0;
}
_______________________________________________
Linux-audio-dev mailing list
Linux-audio-dev@lists.linuxaudio.org
http://lists.linuxaudio.org/listinfo/linux-audio-dev