File tree 1 file changed +10
-25
lines changed
1 file changed +10
-25
lines changed Original file line number Diff line number Diff line change @@ -123,35 +123,20 @@ s32 PcgRandom::range(s32 min, s32 max)
123
123
124
124
void PcgRandom::bytes (void *out, size_t len)
125
125
{
126
- u32 r;
127
126
u8 *outb = (u8 *)out;
127
+ int bytes_left = 0 ;
128
+ u32 r;
128
129
129
- size_t len_alignment = (uintptr_t )out % sizeof (u32);
130
- if (len_alignment) {
131
- len -= len_alignment;
132
- r = next ();
133
- while (len_alignment--) {
134
- *outb = r & 0xFF ;
135
- outb++;
136
- r >>= 8 ;
130
+ while (len--) {
131
+ if (bytes_left == 0 ) {
132
+ bytes_left = sizeof (u32);
133
+ r = next ();
137
134
}
138
- }
139
135
140
- size_t len_dwords = len / sizeof (u32);
141
- while (len_dwords--) {
142
- r = next ();
143
- *(u32 *)outb = next ();
144
- outb += sizeof (u32);
145
- }
146
-
147
- size_t len_remaining = len % sizeof (u32);
148
- if (len_remaining) {
149
- r = next ();
150
- while (len_remaining--) {
151
- *outb = r & 0xFF ;
152
- outb++;
153
- r >>= 8 ;
154
- }
136
+ *outb = r & 0xFF ;
137
+ outb++;
138
+ bytes_left--;
139
+ r >>= 8 ;
155
140
}
156
141
}
157
142
You can’t perform that action at this time.
0 commit comments