tesirand.pp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. {
  2. $Id$
  3. This program test the random function
  4. It gets 10M random values
  5. that are placed in 10000 windows
  6. and print the number of occurence for each window
  7. and the profile of the distribution
  8. of the counts
  9. - this gave very bad value due to a modulo problem
  10. but after this solved
  11. it still shows strange wings !!
  12. }
  13. program test_random;
  14. uses
  15. {$ifdef go32v2}
  16. dpmiexcp,
  17. {$endif go32v2}
  18. graph;
  19. const max = 1000;
  20. maxint = 10000*max;
  21. var x : array[0..max-1] of longint;
  22. y : array[-100..100] of longint;
  23. mean,level,i : longint;
  24. maxcount,delta,maximum,minimum : longint;
  25. st,st2 : string;
  26. gm,gd : integer;
  27. color : longint;
  28. begin
  29. {$ifdef FPC}
  30. gm:=G640x400x256;
  31. gd:=$ff;
  32. {$else }
  33. gd:=detect;
  34. {$endif }
  35. InitGraph(gd,gm,'\bp\bgi');
  36. {$ifdef FPC}
  37. SetWriteMode(NormalPut or BackPut);
  38. {$endif FPC}
  39. SetColor(red);
  40. color:=blue;
  41. mean:=maxint div max;
  42. for level:=0 to 10 do
  43. begin
  44. for i:=0 to max-1 do
  45. x[i]:=0;
  46. for i:=-100 to 100 do
  47. y[i]:=0;
  48. for i:=0 to maxint-1 do
  49. begin
  50. if level=0 then
  51. inc(x[trunc(random*max)])
  52. else
  53. inc(x[random(max*level) div (level)]);
  54. if i mod (maxint div 10) = 0 then
  55. begin
  56. st:='';
  57. str(i,st);
  58. st:='iteration '+st;
  59. OutTextXY(20,20,st);
  60. {Writeln(stderr,st);}
  61. end;
  62. end;
  63. maximum:=0;
  64. minimum:=$7FFFFFFF;
  65. maxcount:=0;
  66. for i:=0 to max-1 do
  67. begin
  68. if x[i]>maximum then
  69. maximum:=x[i];
  70. if x[i]<minimum then
  71. minimum:=x[i];
  72. if abs(x[i]-mean)<100 then
  73. inc(y[x[i]-mean]);
  74. end;
  75. if maximum=0 then
  76. inc(maximum);
  77. for i:=-100 to 100 do
  78. if y[i]>maxcount then
  79. maxcount:=y[i];
  80. if maxcount=0 then
  81. inc(maxcount);
  82. OutTextXY(GetMaxX div 2,GetMaxY-30,'Random Test Program');
  83. str(level,st);
  84. st:='Level '+st;
  85. OutTextXY(30,GetMaxY-60,st);
  86. str(maximum,st);
  87. str(minimum,st2);
  88. st:='Maximum = '+st+' Minimum ='+st2;
  89. OutTextXY(30,GetMaxY-30,st);
  90. for i:=0 to max-1 do
  91. putpixel( (i*getmaxX) div max,
  92. GetMaxY-(x[i]*getMaxY) div (2*mean), color);
  93. inc(color);
  94. setColor(color);
  95. delta:=maximum-minimum+1;
  96. for i:=-100 to 100 do
  97. begin
  98. if i=minimum then
  99. moveto( ((i+100)*getMaxX) div 201,
  100. GetMaxY-(y[i]*getMaxY) div maxcount)
  101. else
  102. lineto( ((i+100)*getMaxX) div 201,
  103. GetMaxY-(y[i]*getMaxY) div maxcount);
  104. if y[i]>0 then
  105. circle( ((i+100)*getMaxX) div 201,
  106. GetMaxY-(y[i]*getMaxY) div maxcount,5);
  107. end;
  108. readln;
  109. inc(color);
  110. end;
  111. CloseGraph;
  112. end.
  113. {
  114. $Log$
  115. Revision 1.2 1998-11-23 23:44:52 pierre
  116. + several bugs converted
  117. }