-
Notifications
You must be signed in to change notification settings - Fork 1
/
2006-May.txt
3841 lines (3488 loc) · 126 KB
/
2006-May.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
From p637777 at aol.com Mon May 1 15:04:33 2006
From: p637777 at aol.com (Markus Engel)
Date: Mon, 1 May 2006 15:04:33 +0200
Subject: [Supertux-devel] Infoboxes
Message-ID: <000001c66d1f$ce75acb0$2001a8c0@homepc01>
Hello!
I have rewritten the patch for the infoboxes. Now it loads all images in the
infobox and checks their size, then it divides it by 16 to get the number of
lines they use.
Markus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: infobox.diff
Type: application/octet-stream
Size: 3013 bytes
Desc: not available
URL: <https://lists.berlios.de/pipermail/supertux-devel/attachments/20060501/d6c0b551/attachment.obj>
From allen at a-king.us Mon May 1 14:55:58 2006
From: allen at a-king.us (Allen King)
Date: Mon, 01 May 2006 08:55:58 -0400
Subject: [Supertux-devel] dev version bug
In-Reply-To: <[email protected]>
References: <[email protected]> <[email protected]> <[email protected]> <[email protected]> <[email protected]>
Message-ID: <[email protected]>
Joth,
Mission accomplished -- grats! Your test exposed a flaw in my thinking
Ryan,
In going to an architecture-independent random number
implementation, I was still using the architecture-dependent variable
RAND_MAX. In Joth's setup, apparently RAND_MAX was 0x7fff, and not
equal to INT_MAX (which was 0x7fffffff, since the program passed an
assert(sizeof(int) >= 4); )
This insight exposes an error the patch will induce in the
randf(...) routines -- they will produce numbers 65,536.0 times too big!
Attached is a RandomGenerator.patch3b fixes this problem, and also
contains all of the changes in RandomPatch.3, since r3478 seemed to have
none of them yet.
Joth Esmo wrote:
> Greetings,
>
> Thanks for clearing everything up. Attached is random_generator.cpp
> with the stderr file. In case you can't access it, here's the
> important stuff:
>
> ==== srand(1146426740) ( 0) RAND_MAX=7fff =====
> ERROR: x=44551574, x0=0, RAND_MAX=7fff
> Assertion failed: 0, file src/random_generator.cpp, line 77
>
> Regards,
> Joth
>
> On 4/29/06, Allen King <allen at a-king.us> wrote:
>> Joth,
>>
>> Thanks for getting back to me so quickly, and with all the right
>> data.
>>
>> There may have been a mis-understanding. The experiment I'm asking
>> you to do
>> is not to fix your problem, but to produce additional output in the
>> failing
>> mode that will help me isolate another suspected related problem.
>> (Below, I
>> will tell you how to get the code to work, but not here.)
>>
>> So here are some points I want to make very clear. (Sorry if this is
>> obvious, and I'm being blunt.):
>>
>> The newer version of the RandomGenerator::srand method code I sent
>> you also
>> fail. I want it to. As such, that line 72 of random_generator.cpp (the
>> "assert(0);") fails is not a problem for this test, it is good.
>> Line 68 should be of a form "if (x < RAND_MAX)" to duplicate the
>> failure.
>> In particular, it should not be modified to "if (x <= RAND_MAX)", or the
>> failure may change or perhaps go away. ACTION: change line 68 from "<="
>> back to "<", so the failure will be replicated.
>> I see no line like "==== srand(ddd) (ddd) RAND_MAX=xxx =====" (where ddd
>> (xxx) are some decimal (hex) numbers) in your console output. QUESTION:
>> Double and tripple check. Did you perhaps not compile the changes, or
>> not
>> use the patched version when making the new console output?
>> If the above gets you lines like "=====...." above in the console
>> output,
>> you're done, send be back the console and random_generator.cpp, and
>> ignore
>> this. If still no such lines appear, I'm wondering if your console
>> log is
>> only monitoring things to standard error. To get these printouts
>> also on
>> standard error, try changing the string "printf(" to "fprintf(stderr,
>> ", in
>> lines 67 and 71. (You may or may not need to add a "#include <stdio.h>"
>> line to compile properly.) At this point, the routine in question should
>> look like the following:
>> #include <stdio.h>
>>
>> int RandomGenerator::srand(int x) {
>> int x0 = x;
>> while (x == 0) // random seed of zero means
>> x = time(0); // randomize with time
>> fprintf(stderr, "==== srand(%10d) (%10d) RAND_MAX=%x =====\n", x,
>> x0,
>> RAND_MAX);
>>
>> if (x < RAND_MAX) {
>> }
>> else { // only allow
>> posative 31-bit seeds
>> fprintf(stderr, "ERROR: x=%x, x0=%x, RAND_MAX=%x\n", x, x0,
>> RAND_MAX);
>>
>> assert(0);
>> }
>> RandomGenerator::srandom(x);
>> return x; // let caller
>> know seed used
>> }
>>
>> When you get the line with the "====..." in it, send me back the same
>> stuff
>> as before, except don't bother with the config file -- it's good.
>>
>> If you can't get the "====..." line, try commenting out the assert(0)
>> above,
>> and replace the following routine:
>>
>> int RandomGenerator::rand(int v) {
>> assert(v != 0 && v <= RAND_MAX);
>> int rv = RandomGenerator::random();
>> printf("===x= rand(%10d) (%10d) RAND_MAX=%x =x====\n", v, rv,
>> RAND_MAX);
>> fprintf(stderr, "==== rand(%10d) (%10d) RAND_MAX=%x =====\n", v, rv,
>> RAND_MAX);
>> return rv % v;
>> }
>>
>> Short of that, can I have VNC access to your machine? Hopefully it
>> won't
>> get to that!
>>
>> Allen
>>
>> P.S.: To run supertux, use the origional code (without any of the
>> mods I've
>> been feeding to you for debug), and comment out the
>> "assert(x<RAND_MAX);"
>> line.
>>
>> Joth Esmo wrote:
>>
>>
>> int RandomGenerator::srand(int x) {
>> int x0 = x;
>> while (x == 0) // random seed of zero means
>> x = time(0); // randomize with time
>> fprintf(stderr, "==== srand(%10d) (%10d) RAND_MAX=%x =====\n", x,
>> x0,
>> RAND_MAX);
>>
>> if (x < RAND_MAX) {
>> }
>> else { // only allow
>> posative 31-bit seeds
>> fprintf(stderr, "ERROR: x=%x, x0=%x, RAND_MAX=%x\n", x, x0,
>> RAND_MAX);
>>
>> assert(0);
>> }
>> RandomGenerator::srandom(x);
>> return x; // let caller
>> know seed used
>> }
>>
>> When you get the line with the "====..." in it, send me back the same
>> stuff
>> as before, except don't bother with the config file -- it's good.
>>
>> If you can't get the "====..." line, try commenting out the assert(0)
>> above,
>> and replace the following routine:
>>
>> int RandomGenerator::rand(int v) {
>> assert(v != 0 && v <= RAND_MAX);
>> int rv = RandomGenerator::random();
>> printf("===x= rand(%10d) (%10d) RAND_MAX=%x =x====\n", v, rv,
>> RAND_MAX);
>> fprintf(stderr, "==== rand(%10d) (%10d) RAND_MAX=%x =====\n", v, rv,
>> RAND_MAX);
>> return rv % v;
>> }
>>
>> Short of that, can I have VNC access to your machine? Hopefully it
>> won't
>> get to that!
>>
>> Allen
>>
>> P.S.: To run supertux, use the origional code (without any of the
>> mods I've
>> been feeding to you for debug), and comment out the
>> "assert(x<RAND_MAX);"
>> line.
>>
>> Joth Esmo wrote:
>> I replaced the text in the .cpp file as you asked and compiled. The
>> error log (stderr) is attached. Line 72 of random_generator.cpp seems
>> to be the problem (the line being: assert(0);). Also attached is my
>> ./supertux/config file. I start the application by opening MSYS,
>> navigating to my supertux directory, and issuing the command
>> 'supertux.exe -w' (as per the Building on Windows page on the wiki --
>> however the -w has been recently removed).
>>
>> In your email, you asked for the patched version of random_seed.cpp. I
>> assume you meant random_generator.cpp, which is attached.
>>
>> I'm not sure what you mean by 'capable of debug'. Should I debug it
>> and then watch the value of the config variable? I didn't quite
>> understand your meaning.
>>
>> PS> I changed the text in random_generator.cpp to read : x <= RAND_MAX
>> (as you requested).
>>
>> Regards,
>> Joth
>>
>> On 4/29/06, Allen King <allen at a-king.us> wrote:
>> Joth,
>>
>> A new patch to fix that problem is in the works, and should be in svn
>> shortly. Should have been x <= RAND_MAX. For the moment, that line
>> can be
>> commented out, or the < changed to <= .
>>
>> But the fact that this problem happened at all is curious to me, and I
>> suspect another bug lurking nearby. In particular, I would like to
>> understand what about your XP setup caused that assertion error. If
>> RAND_MAX is 0x7fffffff, the largest int32, it would be improbably that
>> time(0) would generate that (unless it's not working). Or perhaps
>> RAND_MAX
>> is smaller.
>>
>> If you can patch to the source code, would you replace the routine in
>> random_generator.cpp with
>> int RandomGenerator::srand(int x) {
>> int x0 = x;
>> while (x == 0) // random seed of zero means
>> x = time(0); // randomize with time
>> printf("==== srand(%10d) (%10d) RAND_MAX=%x =====\n", x, x0,
>> RAND_MAX);
>> if (x < RAND_MAX) {
>> }
>> else { // only allow
>> posative 31-bit
>> seeds
>> printf("ERROR: x=%x, x0=%x, RAND_MAX=%x\n", x, x0, RAND_MAX);
>> assert(0);
>> }
>> RandomGenerator::srandom(x);
>> return x; // let caller
>> know seed used
>> }
>> and recreate the failure. Send me the command line used to invoke
>> supertux,
>> the failing printout (as you did), a copy of your ~/.supertux/config
>> file,
>> and the patched copy of random_seed.cpp. If you are you capable of
>> debug,
>> the variable config->random_seed should be traced. Is it RAND_MAX at
>> the
>> assertion failure? Who sets it that?
>>
>> Thanks for your help on this.
>>
>> Allen
>>
>>
>> Jonathan Campbell wrote:
>>
>> Greetings I just finished compiling the development version of
>> SuperTux (the
>> newest build) and tried to launch it. However, it quits after showing a
>> transparent window. The file stderr has the following: [INFO]
>> src/main.cpp:195 [C:\Documents and
>> Settings\Administrator\.supertux] is in the search path
>> [INFO] src/main.cpp:195 [c:\msys\1.0\build\supertux\/data]
>> is in the search path [INFO] src/main.cpp:429 Component 'controller'
>> finished after 0.2 seconds [INFO] src/main.cpp:68 Couldn't load
>> config file:
>> Couldn't open file 'config': The system cannot find the file
>> specified. ,
>> using default settings [INFO] src/main.cpp:429 Component 'config'
>> finished
>> after 0 seconds [INFO] src/main.cpp:429 Component 'tinygettext' finished
>> after 0.001 seconds [INFO] src/main.cpp:429 Component 'commandline'
>> finished
>> after 0 seconds [INFO] src/main.cpp:429 Component 'audio' finished after
>> 0.202 seconds [INFO] src/main.cpp:429 Component 'video' finished
>> after 0.278
>> seconds [INFO] src/main.cpp:429 Component 'scripting' finished after
>> 0.005
>> seconds [DEBUG] src/tile_manager.cpp:47 Tiles loaded in 0.059 seconds
>> [INFO]
>> src/main.cpp:429 Component 'resources' finished after 0.236 seconds
>> Assertion failed: x < RAND_MAX, file src/random_generator.cpp, line
>> 57 I'm
>> running Windows XP with all updates installed. To compile it, I
>> followed the
>> instructions on this page on the wiki:
>> http://supertux.berlios.de/wiki/index.php/Building_on_Windows
>> Any help would be appreciated. I'd really like to see this new
>> version of
>> SuperTux. Regards, Joth Esmo
>> _______________________________________________
>> Supertux-devel mailing list Supertux-devel at lists.berlios.de
>> http://lists.berlios.de/mailman/listinfo/supertux-devel
>>
>>
>>
>>
>> --
>> Flarbland: Your one and only stop for cheats, articles, comedy and
>> much, much more!
>> http://flarbland.bravehost.com
>> ________________________________
>>
> [INFO] src/main.cpp:195 [C:\Documents and
>> Settings\HP_Administrator\.supertux] is in the search
>> path
> [INFO] src/main.cpp:195
>> [c:\msys\1.0\build\supertux2\/data] is in the search
>> path
> [INFO] src/main.cpp:429 Component 'controller' finished after 0.2
>> seconds
> [WARNING]
>> src/control/joystickkeyboardcontroller.cpp:192 Invalid
>> button '0' in buttonmap
> [WARNING]
>> src/control/joystickkeyboardcontroller.cpp:192 Invalid
>> button '1' in buttonmap
> [INFO] src/main.cpp:429 Component 'config' finished
>> after 0.021 seconds
> [INFO] src/main.cpp:429 Component 'tinygettext' finished
>> after 0 seconds
> [INFO] src/main.cpp:429 Component 'commandline' finished
>> after 0 seconds
> [INFO] src/main.cpp:429 Component 'audio' finished after
>> 0.302 seconds
> [INFO] src/main.cpp:429 Component 'video' finished after 0.432
>> seconds
> [INFO] src/main.cpp:429 Component 'scripting' finished after 0.034
>> seconds
> [DEBUG] src/tile_manager.cpp:47 Tiles loaded in 0.057 seconds
> [INFO]
>> src/main.cpp:429 Component 'resources' finished after 0.217
>> seconds
> Assertion failed: 0, file src/random_generator.cpp, line 72
>
> This
>> application has requested the Runtime to terminate it in an unusual
>> way.
> Please contact the application's support team for more
>> information.
>
>
>
>
>
>
>> ________________________________
>>
> (supertux-config
> (show_fps #f)
> (cheats #f)
> (video
> (fullscreen #t)
>> (width 800)
> (height 600)
> )
> (audio
> (sound_enabled #t)
> (music_enabled
>> #t)
> )
> (control
> (keymap
> (map
> (key 13)
> (control "menu-select")
> )
> (map
>> (key 19)
> (control "pause-menu")
> )
> (map
> (key 27)
> (control "pause-menu")
>> )
> (map
> (key 94)
> (control "console")
> )
> (map
> (key 112)
> (control
>> "pause-menu")
> )
> (map
> (key 271)
> (control "menu-select")
> )
> (map
> (key
>> 273)
> (control "jump")
> )
> (map
> (key 274)
> (control "down")
> )
> (map
> (key
>> 275)
> (control "right")
> )
> (map
> (key 276)
> (control "left")
> )
> (map
> (key
>> 303)
> (control "up")
> )
> (map
> (key 304)
> (control "action")
> )
> )
>> (joystick
> (use_hat #t)
> (axis_x 0)
> (axis_y 1)
> (dead_zone_x 1000)
>> (dead_zone_y 1000)
> (map
> (button 0)
> (control "jump")
> )
> (map
> (button 1)
>> (control "action")
> )
> )
> )
> )
>
>
>
>
>
>> ________________________________
>>
> // $Id: random_generator.cpp 3435 2006-04-26 02:13:42Z sik0fewl $
> //
> // A
>> strong random number generator
> //
> // Copyright (C) 2006 Allen King
> //
>> Copyright (C) 2002 Michael Ringgaard. All rights reserved.
> // Copyright (C)
>> 1983, 1993 The Regents of the University of California.
> //
> // Redistribution
>> and use in source and binary forms, with or without
> // modification, are
>> permitted provided that the following conditions
> // are met:
> //
> // 1.
>> Redistributions of source code must retain the above copyright
> // notice,
>> this list of conditions and the following disclaimer.
> // 2. Redistributions
>> in binary form must reproduce the above copyright
> // notice, this list of
>> conditions and the following disclaimer in the
> // documentation and/or other
>> materials provided with the distribution.
> // 3. Neither the name of the
>> project nor the names of its contributors
> // may be used to endorse or
>> promote products derived from this software
> // without specific prior
>> written permission.
> //
> // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
>> HOLDERS AND CONTRIBUTORS "AS IS" AND
> // ANY EXPRESS OR IMPLIED WARRANTIES,
>> INCLUDING, BUT NOT LIMITED TO, THE
> // IMPLIED WARRANTIES OF MERCHANTABILITY
>> AND FITNESS FOR A PARTICULAR PURPOSE
> // ARE DISCLAIMED. IN NO EVENT SHALL
>> THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
> // FOR ANY DIRECT, INDIRECT,
>> INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
> // DAMAGES (INCLUDING, BUT
>> NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
> // OR SERVICES; LOSS OF USE,
>> DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
> // HOWEVER CAUSED AND ON ANY
>> THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
> // LIABILITY, OR TORT
>> (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
> // OUT OF THE USE OF
>> THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> // SUCH DAMAGE.
>
> //
>> Transliterated into C++ Allen King 060417, from sources on
> //
>> http://www.jbox.dk/sanos/source/lib/random.c.html
>
>
>
> #include
>> <stdexcept>
> #include "random_generator.hpp"
> #include
>> "scripting/squirrel_util.hpp"
>
> RandomGenerator systemRandom; // global
>> random number generator
>
> RandomGenerator::RandomGenerator()
>> {
> assert(sizeof(int) >= 4);
> initialized = 0;
>> initialize();
> }
>
> RandomGenerator::~RandomGenerator()
>> {
> }
>
> /*int RandomGenerator::srand(int x) {
> while (x == 0) // random seed of
>> zero means
> x = time(0); // randomize with time
> assert(x < RAND_MAX); //
>> only allow posative 31-bit seeds
> assert(sizeof(int) >= 4);
> srandom(x);
>> return x; // let caller know seed used
> }*/
>
> int RandomGenerator::srand(int
>> x) {
> int x0 = x;
> while (x == 0) // random seed of zero means
> x = time(0);
>> // randomize with time
> printf("==== srand(%10d) (%10d) RAND_MAX=%x
>> =====\n", x, x0, RAND_MAX);
> if (x <= RAND_MAX) {
> }
> else { // only allow
>> posative 31-bit seeds
> printf("ERROR: x=%x, x0=%x, RAND_MAX=%x\n", x, x0,
>> RAND_MAX);
> assert(0);
> }
> RandomGenerator::srandom(x);
> return x; // let
>> caller know seed used
> }
>
> int RandomGenerator::rand() { return random();
>> }
>
> int RandomGenerator::rand(int v) {
> assert(v != 0 && v <= RAND_MAX); //
>> illegal arg: 0 or too big
> return RandomGenerator::random() % v;
> }
>
> int
>> RandomGenerator::rand(int u, int v) {
> assert(v > u);
> return u +
>> RandomGenerator::rand(v-u);
> }
>
> double RandomGenerator::randf(double v) {
>> float rv;
> while ((rv = (double)RandomGenerator::random() /
>> RAND_MAX * v) >= v)
> ; // never return v!
> return rv;
> }
>
> double
>> RandomGenerator::randf(double u, double v) {
> return u +
>> RandomGenerator::randf(v-u);
> }
>
> //-----------------------------------------------------------------------
> //
>>
> // Copyright (C) 2002 Michael Ringgaard. All rights reserved.
> // Copyright
>> (C) 1983, 1993 The Regents of the University of California.
> //
> //
>> Redistribution and use in source and binary forms, with or without
> //
>> modification, are permitted provided that the following conditions
> // are
>> met:
> //
> // 1. Redistributions of source code must retain the above
>> copyright
> // notice, this list of conditions and the following disclaimer.
>>
> // 2. Redistributions in binary form must reproduce the above copyright
> //
>> notice, this list of conditions and the following disclaimer in the
> //
>> documentation and/or other materials provided with the distribution.
> // 3.
>> Neither the name of the project nor the names of its contributors
> // may be
>> used to endorse or promote products derived from this software
> // without
>> specific prior written permission.
> //
> // THIS SOFTWARE IS PROVIDED BY THE
>> COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
> // ANY EXPRESS OR IMPLIED
>> WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> // IMPLIED WARRANTIES OF
>> MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> // ARE DISCLAIMED. IN
>> NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
> // FOR ANY
>> DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
> //
>> DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
> //
>> OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
> //
>> HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
>> STRICT
> // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
>> ANY WAY
> // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
>> POSSIBILITY OF
> // SUCH DAMAGE.
> //
>
> //**#include <os.h>
>
> //
> // An improved
>> random number generation package. In addition to the standard
> //
>> rand()/srand() like interface, this package also has a special state
>> info
> //
>> interface. The initstate() routine is called with a seed, an array of
> //
>> bytes, and a count of how many bytes are being passed in; this array is
> //
>> then initialized to contain information for random number generation
>> with
> //
>> that much state information. Good sizes for the amount of state
> //
>> information are 32, 64, 128, and 256 bytes. The state can be switched by
> //
>> calling the setstate() routine with the same array as was initiallized
> //
>> with initstate(). By default, the package runs with 128 bytes of state
> //
>> information and generates far better random numbers than a linear
> //
>> congruential generator. If the amount of state information is less than
> //
>> 32 bytes, a simple linear congruential R.N.G. is used.
> //
> // Internally, the
>> state information is treated as an array of longs; the
> // zeroeth element of
>> the array is the type of R.N.G. being used (small
> // integer); the remainder
>> of the array is the state information for the
> // R.N.G. Thus, 32 bytes of
>> state information will give 7 longs worth of
> // state information, which
>> will allow a degree seven polynomial. (Note:
> // the zeroeth word of state
>> information also has some other information
> // stored in it -- see
>> setstate() for details).
> //
> // The random number generation technique is a
>> linear feedback shift register
> // approach, employing trinomials (since
>> there are fewer terms to sum up that
> // way). In this approach, the least
>> significant bit of all the numbers in
> // the state table will act as a
>> linear feedback shift register, and will
> // have period 2^deg - 1 (where deg
>> is the degree of the polynomial being
> // used, assuming that the polynomial
>> is irreducible and primitive). The
> // higher order bits will have longer
>> periods, since their values are also
> // influenced by pseudo-random carries
>> out of the lower bits. The total
> // period of the generator is approximately
>> deg*(2**deg - 1); thus doubling
> // the amount of state information has a
>> vast influence on the period of the
> // generator. Note: the deg*(2**deg - 1)
>> is an approximation only good for
> // large deg, when the period of the shift
>> is the dominant factor.
> // With deg equal to seven, the period is actually
>> much longer than the
> // 7*(2**7 - 1) predicted by this formula.
> //
> //
>> Modified 28 December 1994 by Jacob S. Rosenberg.
> //
>
> //
> // For each of the
>> currently supported random number generators, we have a
> // break value on
>> the amount of state information (you need at least this
> // many bytes of
>> state info to support this random number generator), a degree
> // for the
>> polynomial (actually a trinomial) that the R.N.G. is based on, and
> // the
>> separation between the two lower order coefficients of the trinomial.
>
> void
>> RandomGenerator::initialize() {
>
> #define NSHUFF 100 // To drop part of seed
>> -> 1st value correlation
>
> //static long degrees[MAX_TYPES] = { DEG_0, DEG_1,
>> DEG_2, DEG_3, DEG_4 };
> //static long seps [MAX_TYPES] = { SEP_0, SEP_1,
>> SEP_2, SEP_3, SEP_4 };
>
> degrees[0] = DEG_0;
> degrees[1] = DEG_1;
>> degrees[2] = DEG_2;
> degrees[3] = DEG_3;
> degrees[4] = DEG_4;
>
> seps [0] =
>> SEP_0;
> seps [1] = SEP_1;
> seps [2] = SEP_2;
> seps [3] = SEP_3;
> seps [4] =
>> SEP_4;
>
> //
> // Initially, everything is set up as if from:
> //
> // initstate(1,
>> randtbl, 128);
> //
> // Note that this initialization takes advantage of the
>> fact that srandom()
> // advances the front and rear pointers 10*rand_deg
>> times, and hence the
> // rear pointer which starts at 0 will also end up at
>> zero; thus the zeroeth
> // element of the state information, which contains
>> info about the current
> // position of the rear pointer is just
> //
> //
>> MAX_TYPES * (rptr - state) + TYPE_3 == TYPE_3.
>
> randtbl[ 0] = TYPE_3;
>> randtbl[ 1] = 0x991539b1;
> randtbl[ 2] = 0x16a5bce3;
> randtbl[ 3] =
>> 0x6774a4cd;
> randtbl[ 4] = 0x3e01511e;
> randtbl[ 5] = 0x4e508aaa;
> randtbl[
>> 6] = 0x61048c05;
> randtbl[ 7] = 0xf5500617;
> randtbl[ 8] = 0x846b7115;
>> randtbl[ 9] = 0x6a19892c;
> randtbl[10] = 0x896a97af;
> randtbl[11] =
>> 0xdb48f936;
> randtbl[12] = 0x14898454;
> randtbl[13] = 0x37ffd106;
>> randtbl[14] = 0xb58bff9c;
> randtbl[15] = 0x59e17104;
> randtbl[16] =
>> 0xcf918a49;
> randtbl[17] = 0x09378c83;
> randtbl[18] = 0x52c7a471;
>> randtbl[19] = 0x8d293ea9;
> randtbl[20] = 0x1f4fc301;
> randtbl[21] =
>> 0xc3db71be;
> randtbl[22] = 0x39b44e1c;
> randtbl[23] = 0xf8a44ef9;
>> randtbl[24] = 0x4c8b80b1;
> randtbl[25] = 0x19edc328;
> randtbl[26] =
>> 0x87bf4bdd;
> randtbl[27] = 0xc9b240e5;
> randtbl[28] = 0xe9ee4b1b;
>> randtbl[29] = 0x4382aee7;
> randtbl[30] = 0x535b6b41;
> randtbl[31] =
>> 0xf3bec5da;
>
> // static long randtbl[DEG_3 + 1] =
> // {
> // TYPE_3;
> //
>> 0x991539b1, 0x16a5bce3, 0x6774a4cd, 0x3e01511e, 0x4e508aaa, 0x61048c05,
> //
>> 0xf5500617, 0x846b7115, 0x6a19892c, 0x896a97af, 0xdb48f936, 0x14898454,
> //
>> 0x37ffd106, 0xb58bff9c, 0x59e17104, 0xcf918a49, 0x09378c83, 0x52c7a471,
> //
>> 0x8d293ea9, 0x1f4fc301, 0xc3db71be, 0x39b44e1c, 0xf8a44ef9, 0x4c8b80b1,
> //
>> 0x19edc328, 0x87bf4bdd, 0xc9b240e5, 0xe9ee4b1b, 0x4382aee7, 0x535b6b41,
> //
>> 0xf3bec5da
> // };
>
>
> //
> // fptr and rptr are two pointers into the state info,
>> a front and a rear
> // pointer. These two pointers are always rand_sep places
>> aparts, as they
> // cycle cyclically through the state information. (Yes,
>> this does mean we
> // could get away with just one pointer, but the code for
>> random() is more
> // efficient this way). The pointers are left positioned as
>> they would be
> // from the call
> //
> // initstate(1, randtbl, 128);
> //
> // (The
>> position of the rear pointer, rptr, is really 0 (as explained above
> // in
>> the initialization of randtbl) because the state table pointer is set
> // to
>> point to randtbl[1] (as explained below).
> //
>
> fptr = &randtbl[SEP_3 + 1];
>> rptr = &randtbl[1];
>
> //
> // The following things are the pointer to the state
>> information table, the
> // type of the current generator, the degree of the
>> current polynomial being
> // used, and the separation between the two
>> pointers. Note that for efficiency
> // of random(), we remember the first
>> location of the state information, not
> // the zeroeth. Hence it is valid to
>> access state[-1], which is used to
> // store the type of the R.N.G. Also, we
>> remember the last location, since
> // this is more efficient than indexing
>> every time to find the address of
> // the last element to see if the front
>> and rear pointers have wrapped.
> //
>
> state = &randtbl[1];
> rand_type =
>> TYPE_3;
> rand_deg = DEG_3;
> rand_sep = SEP_3;
> end_ptr = &randtbl[DEG_3 +
>> 1];
>
> }
>
> //
> // Compute x = (7^5 * x) mod (2^31 - 1)
> // wihout overflowing 31
>> bits:
> // (2^31 - 1) = 127773 * (7^5) + 2836
> // From "Random number
>> generators: good ones are hard to find",
> // Park and Miller, Communications
>> of the ACM, vol. 31, no. 10,
> // October 1988, p. 1195.
> //
>
> __inline static
>> long good_rand(long x)
> {
> long hi, lo;
>
> // Can't be initialized with 0, so
>> use another value.
> if (x == 0) x = 123459876;
> hi = x / 127773;
> lo = x %
>> 127773;
> x = 16807 * lo - 2836 * hi;
> if (x < 0) x += 0x7fffffff;
> return
>> x;
> }
>
> //
> // srandom
> //
> // Initialize the random number generator based on
>> the given seed. If the
> // type is the trivial no-state-information type,
>> just remember the seed.
> // Otherwise, initializes state[] based on the given
>> "seed" via a linear
> // congruential generator. Then, the pointers are set to
>> known locations
> // that are exactly rand_sep places apart. Lastly, it cycles
>> the state
> // information a given number of times to get rid of any initial
>> dependencies
> // introduced by the L.C.R.N.G. Note that the initialization of
>> randtbl[]
> // for default usage relies on values produced by this
>> routine.
>
> void RandomGenerator::srandom(unsigned long x)
> {
>> long i, lim;
>
> state[0] = x;
> if (rand_type == TYPE_0)
> lim = NSHUFF;
> else
>>
> {
> for (i = 1; i < rand_deg; i++) state[i] = good_rand(state[i - 1]);
>> fptr = &state[rand_sep];
> rptr = &state[0];
> lim = 10 * rand_deg;
> }
>
>> initialized = 1;
> for (i = 0; i < lim; i++) random();
> }
>
> #ifdef
>> NOT_FOR_SUPERTUX // use in supertux doesn't require these methods,
> // which
>> are not portable to as many platforms as
> // SDL. The cost is that the
>> variability of the
> // initial seed is reduced to only 32 bits of
> //
>> randomness, seemingly enough. PAK 060420
> //
> // srandomdev
> //
> // Many