home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.asm.x86      Ahh, the lost art of x86 assembly      4,675 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 3,224 of 4,675   
   aen@nospicedham.spamtrap.com to All   
   Backward LCG   
   08 Jan 18 08:40:56   
   
   Hi!   
      
   I noticed that linear congruential generators can easily be run   
   backwards by using the multiplicative inverse, and am surprised that   
   this isn't mentioned in any text on random numbers.   
      
   Here is an example for a 64-bit LCG: (no usage example, because this   
   only distracts from the point, as I've seen with previous examples).   
      
   AFAIK this LCG is used in the C newlib, and it seems logical to   
   provide a rrand function as well.   
      
             .data   
   X:        .quad     1   
   a:        .quad     6364136223846793005   
   m:	  .quad	    13877824140714322085   
      
             .text   
             .align    16   
   #         Run forward.   
   rand:     mov       rax,[X]   
             mul       qword ptr [a]   
             add       rax,1   
             mov       [X],rax   
             ret   
      
             .align    16   
   #         Run backward.   
   rrand:    mov       rax,[X]   
             sub       rax,1   
             mul       qword ptr [m]   
             mov       [X],rax   
             ret   
   --   
   aen   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca