Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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:
- push af
- call prng24
- ex de,hl
- pop af
- or a \ sbc hl,hl
- ld b,h
- add a,a \ jr nc,$+5 \ push de \ pop hl
- 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
- prng24:
- ;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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement