Sunday, October 02, 2022

Random 0 to 1, Bjork Dream

Rather a slow day yesterday. I spent the morning working on a random number generator that sort of hacks the IEEE float format in a quest for greater speed than a float-int converter:

// Return a float random number >=0 and <1
float floatrandom(void)
{
 union
 {
  lword number;
  float result;
 };
// Multiply seeds
 seed=seed*196314165+907633515;
// Mask float to create any number between 1 and <2
 number=0x3f800000|(seed&0x007fffff);
 return(result-1);
}

It seems to work well enough for white noise, but was, actually, slower than a normal float-int conversion anyway. I decided to test it using some of the 'diehard' tests, which shows that it's not very 'random' but seems random enough to my ears and basic tests of limits and means. I'd prefer an algorithm that returns a number 0 to 1, so I came up with this:

result=random();
if (result<0.5f)
 return(result);
else
{
 result=random();
 if (result<=0.5f)
  return(result+0.5f);
 else
  return(result);
}

I'm not 100% sure if it's free from bias, I can certainly make one that isn't with a few 1-value returns, but I don't want to slow things with too many more tests. It's clear that 25% of the time the >=0 to <1 range applies, but the plain algorithm always applies that. Anyway, these sort of silly obsessions can waste far too many valuable hours. In the afternoon I had a nice drop off to Ty Pawb and the Wrexham Open, but little other work.

I ate normally at 6pm but the pain of slow digestion gradually grew. At 8pm I felt fine, but at 9pm, started to feel the familiar pain, which became agony by 11pm. I barely slept, unable to rest or lie down, my insides beset with many earthquakes.

I finally slept at 6am and dreamt of meeting Bjork, she visited my house for a music creation session. She seemed rather aloof and snobbish, a class above us, and had a personal assistant. She was due to leave but tested positive for Covid in the door of the auto-taxi, a white car which had two locks on the door which required two negative Covid tests to open. The first test lit a green light on the lock, the second, unexpectedly red, causing her to remain, amazed and inconvenienced.