fork download
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. static uint8_t data[256];
  4. static int index;
  5.  
  6. void init_random()
  7. {
  8. srand(NULL);
  9.  
  10. index = 0;
  11. for (int i = 0; i < 256; ++i)
  12. data[i] = i;
  13.  
  14. // bad choice, use fisher-yates for example
  15. for (int i = 0; i < 10000; ++i)
  16. {
  17. int i1 = rand()%256, i2 = rand()%256;
  18. uint8_t t = data[i1];
  19. data[i1] = data[i2];
  20. data[i2] = t;
  21. }
  22. }
  23.  
  24. uint8_t extract()
  25. {
  26. return data[index++];
  27. }
  28.  
  29.  
  30. int main(void) {
  31. init_random();
  32. for (int i = 0; i < 100; ++i)
  33. printf("%d\n", extract());
  34. }
  35.  
Success #stdin #stdout 0s 2156KB
stdin
Standard input is empty
stdout
233
208
16
207
96
67
45
202
255
15
57
187
70
97
224
169
118
252
18
36
158
94
9
23
108
145
51
253
60
87
26
74
156
8
102
113
200
227
48
193
135
226
35
129
203
100
111
32
81
149
242
191
6
13
228
217
225
212
58
246
195
236
160
151
121
37
205
20
1
238
210
29
132
157
41
250
190
247
114
122
221
150
182
218
142
10
136
185
130
77
143
214
92
140
112
167
63
180
148
52