-1

Is there any specific program in arm assembly code which comes close to generating 32 bit binary random numbers? I need 1000 test cases for a program.

aravind d
  • 21
  • 1
  • 3
  • You should have edited your old question to make it less broad. This is still too broad, and the answer is probably still "the same as compiler output for a normal rand() function". You haven't said anything about performance or quality requirements. Why do you need it in asm? Is there a code-size constraint? (answer there, not on this question) – Peter Cordes Mar 03 '16 at 15:55
  • I need 1000 random 32 bit numbers in two sets so that I can implement an algorithm to go from one number to another. – aravind d Mar 03 '16 at 16:16
  • The comment doesn't really answer any of the questions posted by @PeterCordes. And what does "comes close" mean? If you hunt down (*e.g.*, Google or Wikipedia) a typical random number generator, it will "come close". You might have to do a little work to convert it to ARM assembly, if that's what you really require. – lurker Mar 03 '16 at 17:52
  • Ok Lurker and Peter, you both haven't answered my question. – aravind d Mar 04 '16 at 04:30

1 Answers1

1

In this link is a 32-bit ARM code for a PRNG (xorshift generator): http://hackipedia.org/Platform/3D0/html,%203DO%20SDK%20Documentation/Type%20A/tktfldr/acbfldr/2acbh.html

The basic algorithm is newbit:=bit33 EOR bit20, shift left the 33 bit number and put in newbit at the bottom; this operation is performed for all the newbits needed (ie. 32 bits). The entire operation can be coded compactly by making maximal use of the ARM's barrel shifter:

; enter with seed in R0 (32 bits), R1 (1 bit in least significant bit)
; R2 is used as a temporary register.
; on exit the new seed is in R0 and R1 as before
; Note that a seed of 0 will always produce a new seed of 0.
; All other values produce a maximal length sequence.
;
    TST    R1, R1, LSR #1                       ; top bit into Carry
    MOVS   R2, R0, RRX                          ; 33 bit rotate right
    ADC    R1, R1, R1                           ; carry into lsb of R1
    EOR    R2, R2, R0, LSL #12                  ; (involved!)
    EOR    R0, R2, R2, LSR #20                  ; (similarly involved!)

https://en.wikipedia.org/wiki/Pseudorandom_number_generator

ralf htp
  • 9,149
  • 4
  • 22
  • 34