Get a random value for each sample?

Hello,

Is there a way to get a random value for every sample? Preferably 0…1. What I’m trying to do is hack around the fact that Cycles doesn’t support adding volumes with different anisotropies by color, by just sampling one color at a time. I need some sort of changing value for every sample to be able to do that. I don’t think I can use the noise functions to do this, since they are dependent on some position and I don’t have a way to actually randomly choose one.

this function is commonly used:

#include "stdosl.h"

void rng_seed(output int rng, int seed)
{
  int chash = seed;
  if (chash == 0) chash = 1;
  rng = chash * 891694213;
}

float rng_uniform(output int rng)
{
  float res = rng / float(2137483647) * 0.5 + 0.5;
  rng *= 891694213;
  return res;
}

shader random(output float Value=0.5)
{
  int rng;
  float f=0;
  f = fmod(cellnoise(P*123456.0), 1.0);
  rng_seed(rng, int(f * 2137483647));

  Value=rng_uniform(rng);
}

Awesome, thank you!

{ float res = rng / float(2137483647) * 0.5 + 0.5; rng *= 891694213; return res; }