Jump to content
IGNORED

on ... gosub issue


abaudrand

Recommended Posts

There is another approach you might try. rand MOD 6 is a fairly good distribution. I wrote some code to find this using divison by 6 to get the whole number, then multiplication by 6 followed by subtraction to get the remainder. I then increased it by 1 to get a number of 1 to 6.

 

 

It is slower than using a look up table of course, but it saves bytes and is faster than the worse time case of looped division. So it is a medium length time/bytes approach to try and get the most bang for the buck. Try it out. :)

 

Thanks for the code. Division by N-- or a mod N function-- is the solution I generally prefer, whether by actual division, repeated subtraction, or (in a higher language) an actual MOD function call. If I remember correctly, bB's division routine does save the remainder in one of the temp variables (I forget which one), so you can also use that as a sort of built-in mod function.

 

The reason I decided to try a lookup table was for speed, and then I thought of using two different tables so the three extra values from each table could make use of the extra values and still get an even distribution. It does require a bit more ROM, but I think ROM is cheaper to come by than cycles-- unless you're writing a 2K or 4K game.

 

It would be nice to do an analysis of different methods to document the average cycles used (as well as min and max cycles used), plus the distribution for each value. If I remember correctly, this has been discussed before in other threads, but I don't know if anyone ever collected it all into an actual document for reference purposes.

 

I need to go back and look at the rand16 option again, because I forget the details of which values it produces (0 to 255, or just 1 to 255 as rand does), plus how many calls it takes for the "random" sequence to start repeating itself.

Link to comment
Share on other sites

I noticed when I used AND with rand instead of dividing, the distribution was very uneven. When I switched to dividing or a mix of AND and dividing, the distribution became more even.

 

For example, instead of using something like a = (rand&3) + (rand&1) + (rand&1), I had to use something like a = (rand/64) + (rand&1) + (rand/128).

I would have thought that AND gives pretty good results, at least if you're using it by itself (i.e., not combining it with addition). But yes, if you add multiple AND values together then it would throw off the distribution.

 

I wonder if the distribution might be better if you use just one call to rand-- something like this?

 

  a=rand
  b=(a&3)+(a&4)/4+(a&8)/8

Link to comment
Share on other sites

I need to go back and look at the rand16 option again, because I forget the details of which values it produces (0 to 255, or just 1 to 255 as rand does), plus how many calls it takes for the "random" sequence to start repeating itself.

 

 

If it is a LFSR then it should never use zero, as it would get stuck at zero.

 

 

I did a second attempt, and it's much better. I remembered the old fast divide by 3 code from an apple magazine. It was easy to make it divide by six, and I also simplified the multiplication. In short there are no branches now, so it always takes 65 cycles and 41 bytes. You could probably lose more cycles by merging it with the rand routine.

 

 

Here it is:

 

 a = rand

 ASM
;this routine takes any number 1 to 255, do MOD 6, add 1
;produces a value 1 to 6
;requires 65 cycles, 41 bytes

 lda  a   ; holds rand value, 1 to 255
;unsigned division by six
 sta  tempOne
 lsr
 lsr
 adc  tempOne
 ror
 lsr
 adc  tempOne
 ror
 lsr
 adc  tempOne
 ror
 lsr
 adc  tempOne
 ror
 and  #$FC  ; clears carry on the LSR
 lsr

;at this point we have the whole number from division by six  << 1
;now do multiplication by six
 sta  tempOne
 adc  tempOne
 adc  tempOne
 sbc  #0  ; decrease value by 1, so remainder range will be 1 to 6
 sta  tempOne

;finally, find the remainder...
 lda  a  ; holds 1 to 255
 sec
 sbc  tempOne
 sta  a  ; now holds 1 to 6
END

 

 

Edit: shortened the code, at 65 cycles and 41 bytes now!

Edited by Omegamatrix
Link to comment
Share on other sites

Instead of assembly voodoo (because I don't know how) I usually mix in other game variables. Sometimes I call the rand function once per game, stuff it into a variable named gameseed and just shift around bits using existing variables. Check out how I change the color of a dungeon level in Destiny:

change_dungeon_color
tempvar{1} = dungeonlvl{1}
tempvar{2} = 1
rem Setting bits 2 and 3 to 1 keeps things bright
tempvar{3} = 1
tempvar{4} = gameseed{5}
tempvar{5} = dungeonlvl{0}
tempvar{6} = gameseed{1}
tempvar{7} = dungeonlvl{1}

 

tempvar ends up with a nice playfield color due to a bit of bitshifting instead of constantly calling a rand function. Real randomness usually means complicated code. The trick is to make things seem random enough to the player without committing to complicated code. Mixing in game variables and bitshifting is one answer.

 

Another technique is to mix in a timer/counter variable. At the top of the main game loop I have something like:

 

counter = counter + 1

 

You can insert various bits from that counter variable to make your bit-shifting based randomizer seem more random.

Edited by theloon
Link to comment
Share on other sites

If it is a LFSR then it should never use zero, as it would get stuck at zero.

 

I modified my program to use rand16 again, and to stop rolling the dice as soon as either one is 96 (the opcode for RTS, which is the 0 byte value for table0). I also removed the update to the counter so it rolls the dice on every frame to speed up the process. Sometimes it hits 96 right away, and sometimes it runs for a bit before hitting 96, but it does hit 96 eventually, which means the rand function returned a value of 0:

 

  rem * generate a random number from 1 to 6 with equal chances
  dim die1 = a
  dim die2 = b
  dim roll1 = c
  dim roll2 = d
  dim counter = e
  dim rand16 = f
  rem * roll1 and roll2 are used to track whether to use table0 or
  rem * table1 when looking up the mod 6 value for die1 and die2
  scorecolor=$14
loop
  if counter = 0 then gosub rolldice
loop2
  drawscreen
  if die1=96 then goto loop2
  if die2=96 then goto loop2
rem    counter=counter+1:counter=counter&63
  goto loop
rolldice
  rem * roll the first die
  temp1=rand
  roll1=roll1^1
  if roll1=0 then die1=table0[temp1] else die1=table1[temp1]
  rem * roll the second die
  temp1=rand
  roll2=roll2^1
  if roll2=0 then die2=table0[temp1] else die2=table1[temp1]
  score=0
  for temp1=1 to die1:score=score+1000:next
  for temp1=1 to die2:score=score+1:next
  scorecolor=scorecolor+128
  asm
table0
  rts
  byte 1,2
table1
  byte 3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6
  byte 1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4
  byte 5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2
  byte 3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6
  byte 1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4
  byte 5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2
  byte 3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6
  byte 1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4
  byte 5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2
  byte 3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6
  byte 1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4
  byte 5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2
  byte 3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6
  byte 1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4
  byte 5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2
  byte 3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6
end

Link to comment
Share on other sites

If it is a LFSR then it should never use zero, as it would get stuck at zero.

 

I modified my program to use rand16 again, and to stop rolling the dice as soon as either one is 96 (the opcode for RTS, which is the 0 byte value for table0). I also removed the update to the counter so it rolls the dice on every frame to speed up the process. Sometimes it hits 96 right away, and sometimes it runs for a bit before hitting 96, but it does hit 96 eventually, which means the rand function returned a value of 0:

 

Was the seed for the LFSR 0? This is what I mean

Link to comment
Share on other sites

Here's a simpler test. If you take out the dim the screen will always be green. If you include the dim the screen will eventually turn red. If you include the dim but take out the second if then screen will flash red every so often and then go back to green. This indicates that using rand16 does return a value of 0 every now and then.

 

  rem * rand 0?
  dim rand16 = b
loop
  a=rand
  if a=0 then COLUBK=$44 else COLUBK=$C4
loop2
  drawscreen
  if a=0 then loop2
  goto loop

Link to comment
Share on other sites

How about leaving rand out of it altogether?

 set smartbranching on
set romsize 16k
set kernel_options no_blank_lines

dim counter = a
dim randval = b
scorecolor = $0E

main
if joy0fire then gosub rscore
drawscreen
goto main

rscore
randval = randval + counter + randval
score = 0 : score = score + randval
return

vblank
counter = counter + 1
return

Edited by theloon
Link to comment
Share on other sites

I took a look and found the rand routine in std_routines.asm

 

 

randomize
lda rand
lsr
ifconst rand16
rol rand16
endif
bcc noeor
eor #$B4
noeor
sta rand
ifconst rand16
eor rand16
endif
RETURN

 

 

So rand16 seems to be using 2 zero page ram locations. I am assuming rand16 is a variable simply because it begins in lowercase, and hoping that it is following convention.

 

 

But I looked in 2600basic.h and only found rand set to address $A2. I can't find where rand16 is yet. Anyhow maybe the modified code for using rand16 was to allow for a zero to be produced from time to time? It makes sense that way.

Link to comment
Share on other sites

On rand16...Its the user's choice to define the memory location in their bB code.

 

If they don't, bB uses an 8-bit LFSR. If they do, bB uses a 16-bit LFSR.

 

The rand command returns the lower byte of the LFSR, if its 16-bit. That's why its often zero.(The higher byte won't be zero at the same time)

Link to comment
Share on other sites

I took a look at rand (but not rand16), and ran through all the combinations in excel. If rand is seeded with zero, it will be permanently stuck at zero. This is as I expected. Any other number (1 to 255) will produce a different number. All numbers (1 to 255) eventually get produced by rand.

 

 

seed ==> output from rand
 0 ==>   0
 1 ==> 180
 2 ==>   1
 3 ==> 181
 4 ==>   2
 5 ==> 182
 6 ==>   3
 7 ==> 183
 8 ==>   4
 9 ==> 176
10 ==>   5
11 ==> 177
12 ==>   6
13 ==> 178
14 ==>   7
15 ==> 179
16 ==>   8
17 ==> 188
18 ==>   9
19 ==> 189
20 ==>  10
21 ==> 190
22 ==>  11
23 ==> 191
24 ==>  12
25 ==> 184
26 ==>  13
27 ==> 185
28 ==>  14
29 ==> 186
30 ==>  15
31 ==> 187
32 ==>  16
33 ==> 164
34 ==>  17
35 ==> 165
36 ==>  18
37 ==> 166
38 ==>  19
39 ==> 167
40 ==>  20
41 ==> 160
42 ==>  21
43 ==> 161
44 ==>  22
45 ==> 162
46 ==>  23
47 ==> 163
48 ==>  24
49 ==> 172
50 ==>  25
51 ==> 173
52 ==>  26
53 ==> 174
54 ==>  27
55 ==> 175
56 ==>  28
57 ==> 168
58 ==>  29
59 ==> 169
60 ==>  30
61 ==> 170
62 ==>  31
63 ==> 171
64 ==>  32
65 ==> 148
66 ==>  33
67 ==> 149
68 ==>  34
69 ==> 150
70 ==>  35
71 ==> 151
72 ==>  36
73 ==> 144
74 ==>  37
75 ==> 145
76 ==>  38
77 ==> 146
78 ==>  39
79 ==> 147
80 ==>  40
81 ==> 156
82 ==>  41
83 ==> 157
84 ==>  42
85 ==> 158
86 ==>  43
87 ==> 159
88 ==>  44
89 ==> 152
90 ==>  45
91 ==> 153
92 ==>  46
93 ==> 154
94 ==>  47
95 ==> 155
96 ==>  48
97 ==> 132
98 ==>  49
99 ==> 133
100 ==>  50
101 ==> 134
102 ==>  51
103 ==> 135
104 ==>  52
105 ==> 128
106 ==>  53
107 ==> 129
108 ==>  54
109 ==> 130
110 ==>  55
111 ==> 131
112 ==>  56
113 ==> 140
114 ==>  57
115 ==> 141
116 ==>  58
117 ==> 142
118 ==>  59
119 ==> 143
120 ==>  60
121 ==> 136
122 ==>  61
123 ==> 137
124 ==>  62
125 ==> 138
126 ==>  63
127 ==> 139
128 ==>  64
129 ==> 244
130 ==>  65
131 ==> 245
132 ==>  66
133 ==> 246
134 ==>  67
135 ==> 247
136 ==>  68
137 ==> 240
138 ==>  69
139 ==> 241
140 ==>  70
141 ==> 242
142 ==>  71
143 ==> 243
144 ==>  72
145 ==> 252
146 ==>  73
147 ==> 253
148 ==>  74
149 ==> 254
150 ==>  75
151 ==> 255
152 ==>  76
153 ==> 248
154 ==>  77
155 ==> 249
156 ==>  78
157 ==> 250
158 ==>  79
159 ==> 251
160 ==>  80
161 ==> 228
162 ==>  81
163 ==> 229
164 ==>  82
165 ==> 230
166 ==>  83
167 ==> 231
168 ==>  84
169 ==> 224
170 ==>  85
171 ==> 225
172 ==>  86
173 ==> 226
174 ==>  87
175 ==> 227
176 ==>  88
177 ==> 236
178 ==>  89
179 ==> 237
180 ==>  90
181 ==> 238
182 ==>  91
183 ==> 239
184 ==>  92
185 ==> 232
186 ==>  93
187 ==> 233
188 ==>  94
189 ==> 234
190 ==>  95
191 ==> 235
192 ==>  96
193 ==> 212
194 ==>  97
195 ==> 213
196 ==>  98
197 ==> 214
198 ==>  99
199 ==> 215
200 ==> 100
201 ==> 208
202 ==> 101
203 ==> 209
204 ==> 102
205 ==> 210
206 ==> 103
207 ==> 211
208 ==> 104
209 ==> 220
210 ==> 105
211 ==> 221
212 ==> 106
213 ==> 222
214 ==> 107
215 ==> 223
216 ==> 108
217 ==> 216
218 ==> 109
219 ==> 217
220 ==> 110
221 ==> 218
222 ==> 111
223 ==> 219
224 ==> 112
225 ==> 196
226 ==> 113
227 ==> 197
228 ==> 114
229 ==> 198
230 ==> 115
231 ==> 199
232 ==> 116
233 ==> 192
234 ==> 117
235 ==> 193
236 ==> 118
237 ==> 194
238 ==> 119
239 ==> 195
240 ==> 120
241 ==> 204
242 ==> 121
243 ==> 205
244 ==> 122
245 ==> 206
246 ==> 123
247 ==> 207
248 ==> 124
249 ==> 200
250 ==> 125
251 ==> 201
252 ==> 126
253 ==> 202
254 ==> 127
255 ==> 203

Link to comment
Share on other sites

a=rand/2
a=(a/2 + a)/4/4/2+1

 

produces

 

.L00 ;  a = rand / 2
jsr randomize
lsr
STA a
.L01 ;  a =  ( a / 2  +  a )  / 4 / 4 / 2 + 1
; complex statement detected
LDA a
lsr
CLC
ADC a
lsr
lsr
lsr
lsr
lsr
CLC
ADC #1
STA a
.
;

 

 

or in assembly

 

a=rand

asm
lda a
lsr
adc a
and #$C0
rol
rol
rol
adc #$01
sta a
end

Edited by bogax
Link to comment
Share on other sites

Okay, third try. I've gone after MOD 6 plus 1 directly, and had great success. It takes a lot less cycles now, and I have combined the rand call in it too. :)

 

 

So... I've attempted to make a stand alone library called doDiceRoll, which returns a value 1 to 6. I'm not sure if I got the integration syntax right for BB, but lets see! In theory you should be able to add the library and just do a simple call like:

 

 a = doDiceRoll

 

The code itself looks like this:

 

doDiceRoll
;perform rand
 lda  $A2  ; load rand
 lsr
 bcc  .noeor
 eor  #$B4
.noeor:
 sta  $A2  ; rand is updated

;find MOD 6 plus 1
 and  #$30
 lsr
 lsr
 sta  temp1
 lda  $A2
 and  #$0F
 adc  temp1
 tay
 lda  remainderTable,Y
 RETURN

remainderTable:
 .byte 1,2,3,4,5,6
 .byte 1,2,3,4,5,6
 .byte 1,2,3,4,5,6
 .byte 1,2,3,4,5,6
 .byte 1,2,3,4

 

 

I've using temp1, and I'm also using the Y register, so I don't know if that will mess with anything. Another thought is It would be simple to also do a different table of values 0 to 5, and have a constant to switch in-between. Or maybe you could just do:

 

a = doDiceRoll - 1

 

 

Anyhow, and testers out there?

 

diceRoll.asm

Link to comment
Share on other sites

a=rand/2
a=(a/2 + a)/4/4/2+1

Thanks, bogax! If I figured it correctly in Excel, the distribution for bB's standard 8-bit rand function is as follows:

 

1 = 43 (rand = 1 through 43)

2 = 42 (rand = 44 through 85)

3 = 42 (rand = 86 through 127)

4 = 44 (rand = 128 through 171)

5 = 42 (rand = 172 through 213)

6 = 42 (rand = 214 through 255)

Link to comment
Share on other sites

It works well, Omega.

 

Here's a minimal bB program that shows how to use the function. It updates the last score digit with the results of the function once a frame...

 

dim sc2=score+2

scorecolor=$0f

mainloop
sc2=doDiceRoll()
drawscreen
goto mainloop

include diceRoll.asm

 

Also, its better to reference the "rand" label in your function rather than directly using $A2. In the multisprite kernel, rand is $D6

Link to comment
Share on other sites

a=rand/2
a=(a/2 + a)/4/4/2+1

 

produces

 

.L00 ;  a = rand / 2
jsr randomize
lsr
STA a
.L01 ;  a =  ( a / 2  +  a )  / 4 / 4 / 2 + 1
; complex statement detected
LDA a
lsr
CLC
ADC a
lsr
lsr
lsr
lsr
lsr
CLC
ADC #1
STA a
.
;

 

 

or in assembly

 

a=rand

asm
lda a
lsr
adc a
and #$C0
rol
rol
rol
adc #$01
sta a
end

 

 

I just tried it in excel and I got a nice distribution:

 

 

6 => 43

5 => 42

4 => 43

3 => 43

2 => 42

1 => 42

 

Works great and a lot less bytes too. :) But that is for:

 

 

a=rand

a=(a/2 + a)/4/4/2+1

 

When you have rand/2 like so:

 

a=rand/2

a=(a/2 + a)/4/4/2+1

 

you get:

 

 

6 => 0

5 => 0

4 => 0

3 => 86

2 => 84

1 => 85

 

 

So the good code is:

 

 a=rand

 asm
 lda a
 lsr
 adc a
 and #$C0
 rol
 rol
 rol
 adc #$01
 sta a
end

Edited by Omegamatrix
Link to comment
Share on other sites

Here are the values produced for each routine side by side. The number on the left is what rand produces. Then the numbers that follow are the outcomes.

 

---- Bogax - Omega
------------------
255 ---- 6 ---- 4
254 ---- 6 ---- 3
253 ---- 6 ---- 2
252 ---- 6 ---- 1
251 ---- 6 ---- 6
250 ---- 6 ---- 5
249 ---- 6 ---- 4
248 ---- 6 ---- 3
247 ---- 6 ---- 2
246 ---- 6 ---- 1
245 ---- 6 ---- 6
244 ---- 6 ---- 5
243 ---- 6 ---- 4
242 ---- 6 ---- 3
241 ---- 6 ---- 2
240 ---- 6 ---- 1
239 ---- 6 ---- 6
238 ---- 6 ---- 5
237 ---- 6 ---- 4
236 ---- 6 ---- 3
235 ---- 6 ---- 2
234 ---- 6 ---- 1
233 ---- 6 ---- 6
232 ---- 6 ---- 5
231 ---- 6 ---- 4
230 ---- 6 ---- 3
229 ---- 6 ---- 2
228 ---- 6 ---- 1
227 ---- 6 ---- 6
226 ---- 6 ---- 5
225 ---- 6 ---- 4
224 ---- 6 ---- 3
223 ---- 6 ---- 2
222 ---- 6 ---- 1
221 ---- 6 ---- 6
220 ---- 6 ---- 5
219 ---- 6 ---- 4
218 ---- 6 ---- 3
217 ---- 6 ---- 2
216 ---- 6 ---- 1
215 ---- 6 ---- 6
214 ---- 6 ---- 5
213 ---- 6 ---- 4
212 ---- 5 ---- 3
211 ---- 5 ---- 2
210 ---- 5 ---- 1
209 ---- 5 ---- 6
208 ---- 5 ---- 5
207 ---- 5 ---- 4
206 ---- 5 ---- 3
205 ---- 5 ---- 2
204 ---- 5 ---- 1
203 ---- 5 ---- 6
202 ---- 5 ---- 5
201 ---- 5 ---- 4
200 ---- 5 ---- 3
199 ---- 5 ---- 2
198 ---- 5 ---- 1
197 ---- 5 ---- 6
196 ---- 5 ---- 5
195 ---- 5 ---- 4
194 ---- 5 ---- 3
193 ---- 5 ---- 2
192 ---- 5 ---- 1
191 ---- 5 ---- 6
190 ---- 5 ---- 5
189 ---- 5 ---- 4
188 ---- 5 ---- 3
187 ---- 5 ---- 2
186 ---- 5 ---- 1
185 ---- 5 ---- 6
184 ---- 5 ---- 5
183 ---- 5 ---- 4
182 ---- 5 ---- 3
181 ---- 5 ---- 2
180 ---- 5 ---- 1
179 ---- 5 ---- 6
178 ---- 5 ---- 5
177 ---- 5 ---- 4
176 ---- 5 ---- 3
175 ---- 5 ---- 2
174 ---- 5 ---- 1
173 ---- 5 ---- 6
172 ---- 5 ---- 5
171 ---- 5 ---- 4
170 ---- 4 ---- 3
169 ---- 4 ---- 2
168 ---- 4 ---- 1
167 ---- 4 ---- 6
166 ---- 4 ---- 5
165 ---- 4 ---- 4
164 ---- 4 ---- 3
163 ---- 4 ---- 2
162 ---- 4 ---- 1
161 ---- 4 ---- 6
160 ---- 4 ---- 5
159 ---- 4 ---- 4
158 ---- 4 ---- 3
157 ---- 4 ---- 2
156 ---- 4 ---- 1
155 ---- 4 ---- 6
154 ---- 4 ---- 5
153 ---- 4 ---- 4
152 ---- 4 ---- 3
151 ---- 4 ---- 2
150 ---- 4 ---- 1
149 ---- 4 ---- 6
148 ---- 4 ---- 5
147 ---- 4 ---- 4
146 ---- 4 ---- 3
145 ---- 4 ---- 2
144 ---- 4 ---- 1
143 ---- 4 ---- 6
142 ---- 4 ---- 5
141 ---- 4 ---- 4
140 ---- 4 ---- 3
139 ---- 4 ---- 2
138 ---- 4 ---- 1
137 ---- 4 ---- 6
136 ---- 4 ---- 5
135 ---- 4 ---- 4
134 ---- 4 ---- 3
133 ---- 4 ---- 2
132 ---- 4 ---- 1
131 ---- 4 ---- 6
130 ---- 4 ---- 5
129 ---- 4 ---- 4
128 ---- 4 ---- 3
127 ---- 3 ---- 2
126 ---- 3 ---- 1
125 ---- 3 ---- 6
124 ---- 3 ---- 5
123 ---- 3 ---- 4
122 ---- 3 ---- 3
121 ---- 3 ---- 2
120 ---- 3 ---- 1
119 ---- 3 ---- 6
118 ---- 3 ---- 5
117 ---- 3 ---- 4
116 ---- 3 ---- 3
115 ---- 3 ---- 2
114 ---- 3 ---- 1
113 ---- 3 ---- 6
112 ---- 3 ---- 5
111 ---- 3 ---- 4
110 ---- 3 ---- 3
109 ---- 3 ---- 2
108 ---- 3 ---- 1
107 ---- 3 ---- 6
106 ---- 3 ---- 5
105 ---- 3 ---- 4
104 ---- 3 ---- 3
103 ---- 3 ---- 2
102 ---- 3 ---- 1
101 ---- 3 ---- 6
100 ---- 3 ---- 5
-99 ---- 3 ---- 4
-98 ---- 3 ---- 3
-97 ---- 3 ---- 2
-96 ---- 3 ---- 1
-95 ---- 3 ---- 6
-94 ---- 3 ---- 5
-93 ---- 3 ---- 4
-92 ---- 3 ---- 3
-91 ---- 3 ---- 2
-90 ---- 3 ---- 1
-89 ---- 3 ---- 6
-88 ---- 3 ---- 5
-87 ---- 3 ---- 4
-86 ---- 3 ---- 3
-85 ---- 3 ---- 2
-84 ---- 2 ---- 1
-83 ---- 2 ---- 6
-82 ---- 2 ---- 5
-81 ---- 2 ---- 4
-80 ---- 2 ---- 3
-79 ---- 2 ---- 2
-78 ---- 2 ---- 1
-77 ---- 2 ---- 6
-76 ---- 2 ---- 5
-75 ---- 2 ---- 4
-74 ---- 2 ---- 3
-73 ---- 2 ---- 2
-72 ---- 2 ---- 1
-71 ---- 2 ---- 6
-70 ---- 2 ---- 5
-69 ---- 2 ---- 4
-68 ---- 2 ---- 3
-67 ---- 2 ---- 2
-66 ---- 2 ---- 1
-65 ---- 2 ---- 6
-64 ---- 2 ---- 5
-63 ---- 2 ---- 4
-62 ---- 2 ---- 3
-61 ---- 2 ---- 2
-60 ---- 2 ---- 1
-59 ---- 2 ---- 6
-58 ---- 2 ---- 5
-57 ---- 2 ---- 4
-56 ---- 2 ---- 3
-55 ---- 2 ---- 2
-54 ---- 2 ---- 1
-53 ---- 2 ---- 6
-52 ---- 2 ---- 5
-51 ---- 2 ---- 4
-50 ---- 2 ---- 3
-49 ---- 2 ---- 2
-48 ---- 2 ---- 1
-47 ---- 2 ---- 6
-46 ---- 2 ---- 5
-45 ---- 2 ---- 4
-44 ---- 2 ---- 3
-43 ---- 2 ---- 2
-42 ---- 1 ---- 1
-41 ---- 1 ---- 6
-40 ---- 1 ---- 5
-39 ---- 1 ---- 4
-38 ---- 1 ---- 3
-37 ---- 1 ---- 2
-36 ---- 1 ---- 1
-35 ---- 1 ---- 6
-34 ---- 1 ---- 5
-33 ---- 1 ---- 4
-32 ---- 1 ---- 3
-31 ---- 1 ---- 2
-30 ---- 1 ---- 1
-29 ---- 1 ---- 6
-28 ---- 1 ---- 5
-27 ---- 1 ---- 4
-26 ---- 1 ---- 3
-25 ---- 1 ---- 2
-24 ---- 1 ---- 1
-23 ---- 1 ---- 6
-22 ---- 1 ---- 5
-21 ---- 1 ---- 4
-20 ---- 1 ---- 3
-19 ---- 1 ---- 2
-18 ---- 1 ---- 1
-17 ---- 1 ---- 6
-16 ---- 1 ---- 5
-15 ---- 1 ---- 4
-14 ---- 1 ---- 3
-13 ---- 1 ---- 2
-12 ---- 1 ---- 1
-11 ---- 1 ---- 6
-10 ---- 1 ---- 5
--9 ---- 1 ---- 4
--8 ---- 1 ---- 3
--7 ---- 1 ---- 2
--6 ---- 1 ---- 1
--5 ---- 1 ---- 6
--4 ---- 1 ---- 5
--3 ---- 1 ---- 4
--2 ---- 1 ---- 3
--1 ---- 1 ---- 2

Link to comment
Share on other sites

When you have rand/2 like so:

 

a=rand/2

a=(a/2 + a)/4/4/2+1

 

you get:

 

 

6 => 0

5 => 0

4 => 0

3 => 86

2 => 84

1 => 85

 

That's odd

Are you sure you didn't divide by 64?

ie /4/4/4 instead of /4/4/2 ?

 

I reckon it thusly

 

suppose rand returns 255

 

then:

 

rand/2 = 127
a/2 = 63
+ a = 190
/4 = 47
/4 = 11
/2 = 5
+1 = 6

Edited by bogax
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...