POV-Ray : Newsgroups : povray.general : macro always returns zero : Re: macro always returns zero Server Time
6 May 2024 05:29:01 EDT (-0400)
  Re: macro always returns zero  
From: Anthony D  Baye
Date: 25 May 2017 11:20:00
Message: <web.5926f58a2c479cc1fd6b6fe10@news.povray.org>
"stevenvh" <nomail@nomail> wrote:
> I have written this macro to generate integers in [0..A[
>
>  #macro RandInt(A, RS)  floor(A * rand(RS) * 0.999999)  #end
>
> The factor 0.999999 is to ensure A itself is excluded; rand() returns a value in
> [0..1], so including 1.
>
> When I use #debug to see the macro's return value it's fine, but when I assign
> it to a variable, like
>
>  #declare somevar = RandInt(4, Rnd3);
>
> somevar will always be 0. Can anybody explain this, and how to solve it? I've
> written several similar macros which work fine.
>
> TIA
> Steven

I suspect that the problem comes from not reseeding Rand(...) Every time the
macro is called. I'M ve run into this problem myself.

These days, I always use Rand_Normal(...) From rand.inc

Regards,
A.D.B.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.