Jump to content

Bug in srand (Removers standard "C" library)


GroovyBee

Recommended Posts

In the file rand.s the function _srand starts as :-

 

_srand:    
    move.l    d2,-(sp)
    move.l    #random_seeds,a0
    move.l    4(sp),d1
    move.l    d1,d2
    moveq    #RANDGEN_K,d0

 

Which means that the new seed for the random number generator is actually the program counter of the instruction immediately after the "jsr _srand" in your program and not the new seed you passed to the function.

 

It should be changed to :-

 

_srand:    
    move.l    d2,-(sp)
    move.l    #random_seeds,a0
    move.l    4+4(sp),d1
    move.l    d1,d2
    moveq    #RANDGEN_K,d0

 

Link to comment
Share on other sites

In the file rand.s the function _srand starts as :-

 

_srand:    
    move.l    d2,-(sp)
    move.l    #random_seeds,a0
    move.l    4(sp),d1
    move.l    d1,d2
    moveq    #RANDGEN_K,d0

 

Which means that the new seed for the random number generator is actually the program counter of the instruction immediately after the "jsr _srand" in your program and not the new seed you passed to the function.

 

It should be changed to :-

 

_srand:    
    move.l    d2,-(sp)
    move.l    #random_seeds,a0
    move.l    4+4(sp),d1
    move.l    d1,d2
    moveq    #RANDGEN_K,d0

 

Well spotted! Thanks.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...