Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Math bufs (Modulo) & Random Numbers

This topic is 6697 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post

Link to post
Share on other sites
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..)


Share this post

Link to post
Share on other sites
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,

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!