shithub: pokecrystal

Download patch

ref: dbb7431cdef600603252385b8b007e154c4cf220
parent: a7a95e59f7fb9d36d8efdb4cbee4b7fb12775be5
author: yenatch <[email protected]>
date: Sat May 3 17:44:18 EDT 2014

Give a name to RandomRange.

--- a/home/random.asm
+++ b/home/random.asm
@@ -50,26 +50,35 @@
 ; 2fb1
 
 
-Function2fb1:: ; 2fb1
+RandomRange:: ; 2fb1
+; Return a random number between 0 and a (non-inclusive).
+
 	push bc
 	ld c, a
+
+	; b = $100 % c
 	xor a
 	sub c
-.asm_2fb5
+.mod
 	sub c
-	jr nc, .asm_2fb5
+	jr nc, .mod
 	add c
 	ld b, a
+
+	; Get a random number
+	; from 0 to $ff - b.
 	push bc
-.asm_2fbb
+.loop
 	call Random
 	ld a, [hRandomAdd]
 	ld c, a
 	add b
-	jr c, .asm_2fbb
+	jr c, .loop
 	ld a, c
 	pop bc
+
 	call SimpleDivide
+
 	pop bc
 	ret
 ; 2fcb
--- a/main.asm
+++ b/main.asm
@@ -87348,7 +87348,7 @@
 	jr nc, .quit
 
 	ld a, 10
-	call Function2fb1
+	call RandomRange
 	cp 4
 	jr nc, .quit
 
@@ -87631,23 +87631,23 @@
 	ret
 
 .asm_b83f6
-	ld a, $a
-	call Function2fb1
+	ld a, 10
+	call RandomRange
 	and a
 	jr nz, Functionb843b
 	jr Functionb841f
 
 .asm_b8400
-	ld a, $a
-	call Function2fb1
-	cp $5
+	ld a, 10
+	call RandomRange
+	cp 5
 	jr nc, Functionb843b
 	jr Functionb841f
 
 .asm_b840b
-	ld a, $a
-	call Function2fb1
-	cp $8
+	ld a, 10
+	call RandomRange
+	cp 8
 	jr nc, Functionb843b
 	jr .asm_b8416
 
@@ -87663,7 +87663,7 @@
 ; Read a TreeMons table.
 
 	ld a, 100
-	call Function2fb1
+	call RandomRange
 .asm_b8424
 	sub [hl]
 	jr c, .asm_b842c
@@ -99806,8 +99806,8 @@
 
 .asm_fd08b
 	call Functionfd099
-	ld a, $5
-	call Function2fb1
+	ld a, 5
+	call RandomRange
 	inc a
 	ld [$dc18], a
 	scf