-2

Hi I am a new assembly coder and I ran into a problem in my project that I'm fairly certain I know the answer to but I don't know a fix (I've already run the random separately and it works when generating a number one at a time). Problem: When I run the code it fills all the 99 slots with the random num that it chooses one the first random Answer(I think): The random works on the clock so I think the problem is the program is running too fast and already fills the whole timer before the clock changes to the next number Fix: Idk (help me please) Code:

proc ArrayFiller
    push ax 
    push bx
    push cx 
    push dx 
    push si
    
    xor ax, ax 
    xor si, si 
    xor cx, cx 
ArrayLoop:
    call random 
    mov al,[RandomNum]
    mov [CorrectArray+si], al 
    ;call DelayProc
    inc si 
    inc cx
    cmp cx, 99 
    jbe ArrayLoop
    pop si 
    pop dx 
    pop cx
    pop bx 
    pop ax 
    ret
endp ArrayFiller
  • 2
    Is `random` also your code? You should post that too, since if what you say is true, that is where the problem is. "_works on the clock_" - that should not be the case; it is normal to _seed_ a PRNG using _time_, but it should be seeded only once, not on every generation. It sounds like `random` might be re-seeding on every call. – Clifford May 08 '22 at 05:48
  • As Clifford says, I'd guess it doesn't maintain its own state at all so there's nothing to seed. It probably just reads the current time from somewhere and does some operations on those bits. i.e. it's not a PRNG, it's a seed function that you could use to seed the internal state of an actual PRNG. As for how to fix this code, call a non-broken random-number generator! – Peter Cordes May 08 '22 at 06:20
  • 1
    The fun way on a modern x86 CPU is `rdrand ax` https://www.felixcloutier.com/x86/rdrand – Peter Cordes May 08 '22 at 06:45

0 Answers0