Old 20th August 2002, 01:53   #1
KeatonMill
Junior Member
 
Join Date: Jul 2002
Posts: 32
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

code:

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;

KeatonMill is offline   Reply With Quote
Old 20th August 2002, 03:15   #2
Jaheckelsafar
Major Dude
 
Join Date: Feb 2002
Location: home
Posts: 1,318
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.

Stoke me a clipper. I'll be back for Christmas.

- Arnold Rimmer
Red Dwarf
Jaheckelsafar is offline   Reply With Quote
Old 20th August 2002, 11:31   #3
KeatonMill
Junior Member
 
Join Date: Jul 2002
Posts: 32
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)
KeatonMill is offline   Reply With Quote
Old 22nd August 2002, 15:15   #4
UnConeD
Whacked Moderator
 
UnConeD's Avatar
 
Join Date: Jun 2001
Posts: 2,104
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.

UnConeD is offline   Reply With Quote
Old 26th August 2002, 05:49   #5
jim manley
Junior Member
 
jim manley's Avatar
 
Join Date: Aug 2002
Location: A bad neighbourhood in Australia
Posts: 18
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).
jim manley is offline   Reply With Quote
Old 26th August 2002, 11:01   #6
UnConeD
Whacked Moderator
 
UnConeD's Avatar
 
Join Date: Jun 2001
Posts: 2,104
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 .

UnConeD is offline   Reply With Quote
Old 26th August 2002, 20:27   #7
Xion(810)
Major Dude
 
Xion(810)'s Avatar
 
Join Date: Aug 2002
Location: Gran Da Val Island, Ragol
Posts: 1,020
erm...isn't there a rand(var) function? Just a thought.
Xion(810) is offline   Reply With Quote
Old 26th August 2002, 21:00   #8
UnConeD
Whacked Moderator
 
UnConeD's Avatar
 
Join Date: Jun 2001
Posts: 2,104
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.

UnConeD is offline   Reply With Quote
Old 26th August 2002, 21:21   #9
Xion(810)
Major Dude
 
Xion(810)'s Avatar
 
Join Date: Aug 2002
Location: Gran Da Val Island, Ragol
Posts: 1,020
ahhh...
akay...I'll keep checking in maybe I may stumble on something...1 in a million chance of that though...
Xion(810) is offline   Reply With Quote
Old 17th September 2002, 20:35   #10
CrazYdoC
Junior Member
 
CrazYdoC's Avatar
 
Join Date: May 2002
Posts: 4
Send a message via ICQ to CrazYdoC
"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
CrazYdoC is offline   Reply With Quote
Old 18th September 2002, 12:13   #11
UnConeD
Whacked Moderator
 
UnConeD's Avatar
 
Join Date: Jun 2001
Posts: 2,104
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.

UnConeD is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Visualizations > AVS

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump