Link to home
Start Free TrialLog in
Avatar of Greggory

asked on

Psudo Random Number Generator Using Multiple with Over Flow? Or Any Random Number Generator at All?

I need to fill an array with random numbers. I have been looking for the best way to do this and I was told it was fairly easy to do with a big multiple where there is overflow, but I have no idea what I am doing. Any random number generator would work, even linkingi to C. I will end up using this ASM obj file in C anyway. I just need to fill the ASM array with numbers first. Any ideas?
Avatar of grg99

What precision do you need?  16-bit, 32-bit, float?

One way is to start with some big random number, say 3764876862 as the starting value, then multiply it by some prime number, say 4999.  then take as many bytes as you need from the result as your random number.  Use the full result as your next starting value.
Avatar of Greggory


I need 32-bit.

If I start with a big number multiply by a prime, won't I get the same number everytime I run the program?
>f I start with a big number multiply by a prime, won't I get the same number everytime I run the program?

Yes,you'll get the same sequence.  Which is good during debugging.

If you want different results every time, use the time of day as the seed.
Avatar of ozo
can you use srand or rand in your code?
for ASM code, please refer to
Srand or rand as in C and link it? That would be great, but I have no idea how to do that. I heard it was just as easy to do the whole multiply thing, but I don't really know how to do that either. I looked at that message board, but the code by bitRAKE was really confusing. I don't really know what load rule lookup register is. Does it just load some memory spot which contains a number? Then the rest of the code shifts and multiply by various numbers to get something random? When that's done, what has the number; eax, ecx, ord edx?
there are many documents represent how to call C procedure from Asm or vice versa.
if you want to call ASM procedure from you C program, you may at least have two choices,
1. use inline assembler, usually it is:
         // here is your asm code.. mov eax,.....
   _asm mov eax,...
   _asm cmp ...
the reserved directive _asm also could be asm or __asm, it depends on your compiler.
2. you can compile your asm module separately and then link these modules(ASM and C) together.
If you want to call C procedure from you ASM program, you need to use the second method just mentioned above.
You can refer to for detailed informations
Avatar of BeyondWu
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup topic area:
    Accept: BeyondWu {http:#12761360}

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

EE Cleanup Volunteer