Jump to content
Jagware
Sign in to follow this  
GroovyBee

Bug in srand (Removers standard "C" library)

Recommended Posts

GroovyBee    0

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

 

Share this post


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

Share this post


Link to post
Share on other sites
Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoticons maximum are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×