Advertisement

Number Limitation?

Started by July 15, 2000 01:53 PM
0 comments, last by cyberben 24 years, 5 months ago
Hi there, I just today got my random number generator but I''m having a little trouble, the number generator generates a random 16 bit number. Now in VB I do this to limit the random number: Int((Max - Min + 1) * Rnd + Min) Where Rnd is vb''s random number. I think Rnd < 1 & Rnd > 0.001 but I don''t remember exactly (I haven''t used vb in a long time) So now in assembler, I''d like to avoid floats so here''s what I thought: Note: My random number is between 0 & 65535 mov bx, ax ;First put our random number into bx mov ax, Max ;now load our max into ax sub ax, Min ;subtract our min inc ax ;add 1 mul bx ;muliply that by our random number xor edx,edx ;Clear edx for divide mov bx, 10000 ;Move in 10000 for divide (This is to simulate a decimal) div bx ;Divide our random number add ax, Min Now after looking at this I realizes it could max out within the Mul operation if my returned random number was 65535 and it multiplies by any number > 1. So I''m not sure what to do? It allways stays above the minimum with this code, but it''ll go above the max by 3 times! Any help? Thanks, 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
Oh yah, I''m using assembler in case you couldn''t see that! :-)

So it''s not the normal C++ random routines.

But the theory is the same, I got a random 16bit value and need a number between Min and Max which are two passed in parameters (Both 16bit).

Any body even looked at this post?
- 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

This topic is closed to new replies.

Advertisement