Math bufs (Modulo) & Random Numbers
Hi there, I need to write a modulo funcion (In assembler) but I''m having trouble understanding the theory. Here what I could come up with:
http://www.cut-the-knot.com/blue/Modulo.html
It explains it but I don''t get it. Maybe I should read it at a different time than at night... he, he, he :-)
Anyhow the purpose of this is to make a random number generator. It does not have to be "perfectly" random (I guess that''s not possible anyhow) but fast is important and non-linear, so using the milliseconds of the time-stamp is no good! :-)
Anyhelp?
Thanks,
Ben
P.S. I found an old simple equation here:
http://www.physics.carleton.ca/courses/75.502/slides/monte12/P008.html which looked like something I could do, other than this modulo thing... Or does anybody have another assembler random number generator?
__________________________Mencken's Law:"For every human problem, there is a neat, simple solution; and it's always wrong."
"Computers in the future may weigh no more than 1.5 tons."- Popular Mechanics, forecasting the relentless march of science in 1949
"Computers in the future may weigh no more than 1.5 tons."- Popular Mechanics, forecasting the relentless march of science in 1949
It''s really quite easy. The ''%'' operator in C/C++ performs this function.
a % b = k, where k is the remainder of a divided by b.
For example, 35 % 32 = 3 because 35/32 = 1 with remainder 3.
And 7 % 12 = 7 because 7/12 = 0 with remainder 7.
To say "A is congruent to B (Modulo N)" means that N divides evenly into A-B. (Also A % N == B % N, which can be proved mathematically by contradiction.)
Rings and Fields are names for a set of numbers that have certain properties under addition and multiplication. If you want to really learn about all about it, I suggest you take a college course in Abstract Algebra.. Or, talk to someone that''s hip on it.
Hope that helps (a little bit, at least..)
// CHRIS
a % b = k, where k is the remainder of a divided by b.
For example, 35 % 32 = 3 because 35/32 = 1 with remainder 3.
And 7 % 12 = 7 because 7/12 = 0 with remainder 7.
To say "A is congruent to B (Modulo N)" means that N divides evenly into A-B. (Also A % N == B % N, which can be proved mathematically by contradiction.)
Rings and Fields are names for a set of numbers that have certain properties under addition and multiplication. If you want to really learn about all about it, I suggest you take a college course in Abstract Algebra.. Or, talk to someone that''s hip on it.
Hope that helps (a little bit, at least..)
// CHRIS
// CHRIS [win32mfc]
Thanks! I ended up making a slightly different one without modulo in it, and it works great! It runs in only like 50 cpu cycles (Well when you run randomize, it takes a couple hundred cpu cycles to randomize the seed values) and has a period of 2^f*(2^55 - 1) where 0 <= f <= 16, so I''m quite happy, you''ll never notice any patterns with that even if it''s not that good of a random number generator! :-)
See ya,
Ben
See ya,
Ben
__________________________Mencken's Law:"For every human problem, there is a neat, simple solution; and it's always wrong."
"Computers in the future may weigh no more than 1.5 tons."- Popular Mechanics, forecasting the relentless march of science in 1949
"Computers in the future may weigh no more than 1.5 tons."- Popular Mechanics, forecasting the relentless march of science in 1949
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement