- AVS
- Random Number Generators
Archive: Random Number Generators
KeatonMill
20th August 2002 02:53 UTC
Random Number Generators
I'm having a problem with a random number generator I wrote. It's supposed to generate unique x, y, and z coordinates for each point, but it seems to loop values after a while (past a certain point, no more dots are drawn). Here's the code I'm using. Any assistance? Thanks,
~Keaton
PerFrame: sx=17;sy=2;sz=1
PerPoint:
sx=(sx*28626+4120+sy)%2000;
sy=(sy*98387+5311*sz)%2000;
sz=(sz*43198+6421-sx)%2000;
Jaheckelsafar
20th August 2002 04:15 UTC
Sorry, don't know enough about it to really help. Here's one I'm using (if it helps). I just pulled the numbers out of nowhere.
per frame:
xs=17;
per pixel:
xs=(296*xs+123)%500;
x1=xs/500;
How many points are you using? The way yours setup it should generate 2000 values.
KeatonMill
20th August 2002 12:31 UTC
Ideally, I would input as many points as I wanted and I still would get different values out each time (remember that I do have 3 dimensions going on)
UnConeD
22nd August 2002 16:15 UTC
I think you have to use a prime number as your module factor.. or maybe it was using a prime number as multiplication factor.
Anyway usually playing with the constants solves it for me ;)
Btw you seem to be picking awfully large constants. Remember you're working modulo 2000:
sx=(sx*28626+4120+sy)%2000;
sx=(sx*626+120+sy)%2000;
Will be the same.
jim manley
26th August 2002 06:49 UTC
It looks like you're trying to use some kind of hash function. The theory is that you should choose prime numbers (as suggested) but it should also be far from any powers of two. Also, you probably shouldn't mod using values greater than about 4 times the render width (in pixels).
UnConeD
26th August 2002 12:01 UTC
By the way do you know a good page that covers the iterative 'r=(r*a+b)%c' pseudo-random number number generators? Just out of personal interest... I wrote a little PHP script to find series which run a complete range, and I still haven't found a pattern in it ;).
Xion(810)
26th August 2002 21:27 UTC
erm...isn't there a rand(var) function? Just a thought.
UnConeD
26th August 2002 22:00 UTC
The goal here is to have a seedable random number generator which returns the same series of numbers every frame. This is useful for making particle superscopes.
Xion(810)
26th August 2002 22:21 UTC
ahhh...
akay...I'll keep checking in maybe I may stumble on something...1 in a million chance of that though...
CrazYdoC
17th September 2002 21:35 UTC
"documentation"?
hi guys,
i just wondered if one of you could explain to me the idea behind that whole pseudo random number generator stuff shortly (i mean the mathematical idea and the conrete and/but more simple techniques), or maybe a link to a site or a reference to good books about it. I'm sure someone (unconed?) once did post a link to a page about that but i was kinda busy then and now i can't find that post anymore :( and that page also looked kinda complicated, as if you had to spend n months with n->infinite to understand that, that is if you were me ;)
have a nice day
UnConeD
18th September 2002 13:13 UTC
Actually popping 'pseudo-random number generator' into Google should pop-up some interesting things.
The main idea here is to create a series of numbers that are seemingly random. Usually you start from a 'seed': this is an initialiser value and a specific seed will have a certain series of numbers it generates, every time. Usually the seed value is picked from a random source like the current time, or based on human interaction like mouse movement or keyboard typing intervals.
Most random number generators will have a period: after generating 'x' values, they will start returning the same values as in the beginning. The best random number generators have huge periods.
An important requirement is usually that the generated numbers are distributed uniformly, which means that every possible number will have an equal chance of being generated.
We want a series of somewhat random numbers, but that are still constant over time. That way we can create 'clouds' of points and 'remember' the position of every point, because we know the initial seed of the random number generator.
A very simple random number generator (a is the initial seed) is:
a = (a*b) % c
This will generate a random number between 0 and c. Depending on the values b and c, not all numbers in the range 1 .. c will be generated. The period of this generator is of course equal to or smaller than c.