#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- # # File rnd.S Created 04-FEB-1999 Richard B. Johnson # # Simple random number generator. Based upon Alan R. Miller's # algorithm. Professor of Metallurgy, University of New Mexico # Institute of Mining and Technology, circa 1980. Published # In the 8080/Z-80 Assembly Language manual he wrote. # # unsigned size_t rnd((size_t *) seed); # # The seed can be initialized with time(&seed); on each boot. # MAGIC = 0x72b6078b INTPTR = 0x08 DIVISR = 0x0c .section .text .global rnd .type rnd,@function .align 0x04 rnd: pushl %ebx movl INTPTR(%esp), %ebx movl (%ebx), %eax rorl $3, %eax addl $MAGIC, %eax movl %eax, (%ebx) popl %ebx ret #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- # # This returns a random number between 0 and one less than the # input divisor, i.e. n mod rand(x). # # size_t modrnd((size_t *) seed, size_t divisor); # .type modrnd,@function .global modrnd .align 0x04 modrnd: pushl %ebx movl INTPTR(%esp), %ebx movl (%ebx), %eax rorl $3, %eax addl $MAGIC, %eax movl %eax, (%ebx) xorl %edx, %edx divl DIVISR(%esp) movl %edx, %eax popl %ebx ret .end #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-