|
|
rand() returns a value in [0..1[, which is as general as it gets, but I
often need a random value in [A-B..A+B].
Of course I could write
#declare myvar = A + B * ( 2 * rand(rnd) - 1 );
but I would love to have a function, say rand2(), which I could use as e.g.
#declare myvar = rand2(rnd, A, B);
or even
sphere { < rand2(rnd, A, B), rand2(rnd, A, B), rand2(rnd, A, B) >, 100 }
Is this possible? I gather that I can't use rand() in user-defined
functions.
TIA
Steven
Post a reply to this message
|
|
|
|
Wasn't it stevenvh who wrote:
>rand() returns a value in [0..1[, which is as general as it gets, but I
>often need a random value in [A-B..A+B].
>Of course I could write
>
> #declare myvar = A + B * ( 2 * rand(rnd) - 1 );
>
>but I would love to have a function, say rand2(), which I could use as e.g.
>
> #declare myvar = rand2(rnd, A, B);
>
>or even
>
> sphere { < rand2(rnd, A, B), rand2(rnd, A, B), rand2(rnd, A, B) >, 100 }
>
>Is this possible? I gather that I can't use rand() in user-defined
>functions.
You can't use rand in functions, but you can use it in a macro. The
"rand.inc" include file contains this:
//random number in specified range [Min, Max]
#macro RRand(Min, Max, RS) (rand(RS)*(Max-Min) + Min) #end
You can either use that like RRand(A-B,A+B,rs) or write
//random number in specified range [A-B,A+B]
#macro ABRand(A, B, RS) (rand(RS)*2*B + A-B) #end
--
Mike Williams
Gentleman of Leisure
Post a reply to this message
|
|