POV-Ray : Newsgroups : povray.general : Macros and arrays : Re: Macros and arrays Server Time
7 Aug 2024 17:22:08 EDT (-0400)
  Re: Macros and arrays  
From: ingo
Date: 13 Aug 2001 10:13:34
Message: <Xns90FCA510C73Dseed7@povray.org>
in news:3b77cd84@news.povray.org Gail Shaw wrote:

> // very pseudo-code
> 
> #declare ObjectsArray=array[4] {Object1,Object2,Object3,Object4}
> #declare ProbArray = array[4] {0.5,0.2,0.2,0.1}
> 
> Pile(ObjectsArray,ProbArray)
> 
> In the above case 50% of the pile will be object1, 20% object2 etc
> 
> 

You'll have to do it in a few steps:

1. generate a random integer number in the range 0 to len(ProbArray)-1

2. use the resulting number as input for the ProbArray and retreive the 
probability.

3. generate a random number in the range 0-1, check if it is smaller or 
equal to the probability.

4. if no, start all over again.

5 if yes, take the number you found in step two and use it as input in 
the ObjectsArray.



Ingo

-- 
Photography: http://members.home.nl/ingoogni/
Pov-Ray    : http://members.home.nl/seed7/


Post a reply to this message

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