06-19-2012, 12:27 AM
For those that are curious, bored, or obsessive about numbers (me) here are the relative timings for each possible output:
You can clearly see the timings increase as we cross a bit boundary (that is, limit requires more bits). This is because probability of rolling higher than the limit increases here - and decreases fairly linearly until the next bit boundary, when it jumps up.
For values at bitboundary upper limits, if you can, choose the faster route
Limit Frames for 20,000
0 23 (really, you want a number from 0-0? You're going to get 0! There's definitely a faster way of calculating zero...)
1 82 Faster route: baseRandom bAND 1
2 86
3 78
4 89
5 82
6 77
7 74 Faster route: baseRandom bAND 7
8 88
9 84
10 81
11 77
12 75
13 73
14 71
15 69 Faster route: baseRandom bAND 15
16 87
17 84
18 82
19 80
20 78
21 76
22 75
23 73
24 72
25 70
26 69
27 68
28 67
29 66
30 66
31 65 Faster route: baseRandom bAND 31
32 84
33 82
34 80
35 79
36 78
37 77
38 76
39 75
40 74
41 73
42 72
43 71
44 70
45 70
46 69
47 69
48 68
49 67
50 67
51 66
52 66
53 65
54 65
55 64
56 64
57 63
58 63
59 62
60 62
61 61
62 61
63 61 Faster Route: baseRandom bAND 63
64 80
65 79
66 78
67 77
68 77
69 76
70 76
71 75
72 74
73 74
74 73
75 73
76 72
77 71
78 71
79 71
80 70
81 70
82 69
83 69
84 68
85 68
86 68
87 67
88 67
89 66
90 66
91 66
92 65
93 65
94 65
95 64
96 64
97 64
98 63
99 63
100 63
101 62
102 62
103 62
104 61
105 61
106 61
107 61
108 60
109 60
110 60
111 60
112 59
113 59
114 59
115 59
116 59
117 58
118 58
119 58
120 58
121 57
122 57
123 57
124 57
125 57
126 57
127 56 Faster route: baseRandom bAND 127
128 75
129 75
130 75
131 74
132 74
133 73
134 73
135 73
136 72
137 72
138 72
139 72
140 71
141 71
142 70
143 70
144 70
145 69
146 69
147 69
148 69
149 69
150 68
151 68
152 68
153 68
154 67
155 67
156 67
157 67
158 66
159 66
160 66
161 66
162 65
163 65
164 65
165 65
166 65
167 64
168 64
169 64
170 63
171 63
172 63
173 63
174 63
175 63
176 62
177 62
178 62
179 62
180 62
181 61
182 61
183 61
184 61
185 61
186 60
187 60
188 60
189 60
190 60
191 60
192 60
193 59
194 59
195 59
196 59
197 59
198 59
199 58
200 58
201 58
202 58
203 58
204 58
205 58
206 57
207 57
208 57
209 57
210 57
211 57
212 56
213 56
214 56
215 56
216 56
217 56
218 56
219 56
220 56
221 55
222 55
223 55
224 55
225 55
226 55
227 55
228 55
229 54
230 54
231 54
232 54
233 54
234 54
235 54
236 54
237 54
238 54
239 53
240 53
241 53
242 53
243 53
244 53
245 53
246 53
247 53
248 53
249 53
250 52
251 52
252 52
253 52
254 52
255 52 Much faster to use randomBase to get 0-255.
I know. Waaay overboard. Mostly did this just to reassure myself there weren't any exceptionally slow points, or corner cases. There was a bug, which I think I've fixed
In short: I put this forward as a faster random number generator than using floating point numbers.
You can clearly see the timings increase as we cross a bit boundary (that is, limit requires more bits). This is because probability of rolling higher than the limit increases here - and decreases fairly linearly until the next bit boundary, when it jumps up.
For values at bitboundary upper limits, if you can, choose the faster route

Limit Frames for 20,000
0 23 (really, you want a number from 0-0? You're going to get 0! There's definitely a faster way of calculating zero...)
1 82 Faster route: baseRandom bAND 1
2 86
3 78
4 89
5 82
6 77
7 74 Faster route: baseRandom bAND 7
8 88
9 84
10 81
11 77
12 75
13 73
14 71
15 69 Faster route: baseRandom bAND 15
16 87
17 84
18 82
19 80
20 78
21 76
22 75
23 73
24 72
25 70
26 69
27 68
28 67
29 66
30 66
31 65 Faster route: baseRandom bAND 31
32 84
33 82
34 80
35 79
36 78
37 77
38 76
39 75
40 74
41 73
42 72
43 71
44 70
45 70
46 69
47 69
48 68
49 67
50 67
51 66
52 66
53 65
54 65
55 64
56 64
57 63
58 63
59 62
60 62
61 61
62 61
63 61 Faster Route: baseRandom bAND 63
64 80
65 79
66 78
67 77
68 77
69 76
70 76
71 75
72 74
73 74
74 73
75 73
76 72
77 71
78 71
79 71
80 70
81 70
82 69
83 69
84 68
85 68
86 68
87 67
88 67
89 66
90 66
91 66
92 65
93 65
94 65
95 64
96 64
97 64
98 63
99 63
100 63
101 62
102 62
103 62
104 61
105 61
106 61
107 61
108 60
109 60
110 60
111 60
112 59
113 59
114 59
115 59
116 59
117 58
118 58
119 58
120 58
121 57
122 57
123 57
124 57
125 57
126 57
127 56 Faster route: baseRandom bAND 127
128 75
129 75
130 75
131 74
132 74
133 73
134 73
135 73
136 72
137 72
138 72
139 72
140 71
141 71
142 70
143 70
144 70
145 69
146 69
147 69
148 69
149 69
150 68
151 68
152 68
153 68
154 67
155 67
156 67
157 67
158 66
159 66
160 66
161 66
162 65
163 65
164 65
165 65
166 65
167 64
168 64
169 64
170 63
171 63
172 63
173 63
174 63
175 63
176 62
177 62
178 62
179 62
180 62
181 61
182 61
183 61
184 61
185 61
186 60
187 60
188 60
189 60
190 60
191 60
192 60
193 59
194 59
195 59
196 59
197 59
198 59
199 58
200 58
201 58
202 58
203 58
204 58
205 58
206 57
207 57
208 57
209 57
210 57
211 57
212 56
213 56
214 56
215 56
216 56
217 56
218 56
219 56
220 56
221 55
222 55
223 55
224 55
225 55
226 55
227 55
228 55
229 54
230 54
231 54
232 54
233 54
234 54
235 54
236 54
237 54
238 54
239 53
240 53
241 53
242 53
243 53
244 53
245 53
246 53
247 53
248 53
249 53
250 52
251 52
252 52
253 52
254 52
255 52 Much faster to use randomBase to get 0-255.
I know. Waaay overboard. Mostly did this just to reassure myself there weren't any exceptionally slow points, or corner cases. There was a bug, which I think I've fixed

In short: I put this forward as a faster random number generator than using floating point numbers.