Archived

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

Number Limitation?

This topic is 6361 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 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

Share this post


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

Share this post


Link to post
Share on other sites