## Random Point Distribution Problems

Member
Posts: 227
Joined: 2008.08
Post: #1
For a particle engine I need to randomly distribute points within a maximum spread.

My method is this:
Code:
```for each particle in particleArray do:      particle.x=particle.x+randomFrom0To1()*spread;      particle.y=particle.y+randomFrom0To1()*spread;      particle.z=particle.z+randomFrom0To1()*spread;```

However it doesn't seem to be working, so are there any problems with how I am doing it?
Is there any better method?
Moderator
Posts: 1,563
Joined: 2003.10
Post: #2
What are you trying to achieve, and in what way does that implementation fall short of the intended result?

The main thing that pops out to me is that if your random function does what its name implies, you won't get any negative numbers, so you may want to do ((randomFrom0To1() - 0.5) * 2) instead. With more context, we'd probably be able to give you a better answer...
Member
Posts: 227
Joined: 2008.08
Post: #3
I already figured this one out, it had to do with me not taking into consideration that intValue%100/100 will always give 0 as there is no fractional part and it is not implicitly made float (Argh!!! The perils of being high on floats! Hah ha...).
Member
Posts: 46
Joined: 2008.10
Post: #4
Because I'm slightly bored:

You may also want to consider incorporating some form of a distribution function, probably Gaussian, to give your particle system a more realistic look.

Glad you fixed your problem, though!

"Who's John Galt?"