Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- prngSeed:
- ld a,r
- ld h,a
- xor 77
- ld l,a
- ld (seed1),hl
- ld (seed2),hl
- ret
- prng16:
- ;collab with Runer112
- ;;Output:
- ;; HL is a pseudo-random int
- ;; A and BC are also, but much weaker and smaller cycles
- ;; Preserves DE
- ;;148cc, super fast
- ;;26 bytes
- ;;period length: 4,294,901,760
- seed1=$+1
- ld hl,9999
- ld b,h
- ld c,l
- add hl,hl
- add hl,hl
- inc l
- add hl,bc
- ld (seed1),hl
- seed2=$+1
- ld hl,987
- add hl,hl
- sbc a,a
- and %00101101
- xor l
- ld l,a
- ld (seed2),hl
- add hl,bc
- ret
- rand:
- ;;Input: A is the range.
- ;;Output: Returns in A a random number from 0 to (input)A-1.
- ;; B=0
- ;; DE is a pseudo-random 16-bit integer.
- ;;Destroys:
- ;; HL
- ;;Speed:
- ;; 322cc to 373cc, 347.5cc average
- push af
- call prng16
- ex de,hl
- pop af
- ld hl,0
- ld b,h
- add a,a \ jr nc,$+5 \ ld h,d \ ld l,e
- add hl,hl \ rla \ jr nc,$+4 \ add hl,de \ adc a,b
- add hl,hl \ rla \ jr nc,$+4 \ add hl,de \ adc a,b
- add hl,hl \ rla \ jr nc,$+4 \ add hl,de \ adc a,b
- add hl,hl \ rla \ jr nc,$+4 \ add hl,de \ adc a,b
- add hl,hl \ rla \ jr nc,$+4 \ add hl,de \ adc a,b
- add hl,hl \ rla \ jr nc,$+4 \ add hl,de \ adc a,b
- add hl,hl \ rla \ ret nc \ add hl,de \ adc a,b
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement