Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!uunet!nfsun!eklektik!eric From: eric@eklektik.UUCP (/dev/tty000) Newsgroups: comp.sys.amiga Subject: Re: Random sound on Startup... Summary: ARexx's random() has improved. Message-ID: <5055@eklektik.UUCP> Date: 7 Aug 90 15:32:31 GMT References: <1841@lpami.wimsey.bc.ca> Reply-To: eric@eklektik.UUCP (/dev/tty000) Organization: Computers, Gerbils, and Games in the Basement, Pgh, PA Lines: 88 In article <1841@lpami.wimsey.bc.ca> lphillips@lpami.wimsey.bc.ca (Larry Phillips) writes: >with the same seed value for its next call, giving you the same sequence. What >you want to do is to generate the initial seed with the randu() function, and >base it on something that has a fairly good chance of being random enough >with in your application to suit the purpose. Here's your program, modified. >/* Tapestry.rexx -- Randomly choose a picture file for tapestry to display */ >files = showdir("s:pix") >call randu(1000*time('S')) >address command "run tapestry s:pix/"||word(files,random(1,words(files))) >>exit That's essentially the original version of my program. It's essentially the version I posted, too, I just included a custom random function. The problem is, Arexx's random number generator was lousy. I did some controlled tests on it, and it gave extremely non-uniform distributions. I'm not talking about getting the same sequence when starting from the same seed, I'm talking about preferentially obtaining similar numbers over and over, regardless of the seed. I did that a while ago, and posted some results to the net at that time. That's what prompted the discussion leading to the rxandom() function I just posted. I ran those tests under ARexx 1.06. Out of curiousity, I just ran them again under the current version (1.1?). Attached is the test program and the results. /* tstrand.rexx -- test random() */ do i=1 to 100 by 1 /* initialize array for histogram */ histogram.i = 0 end call randu(1000*time('S')) do i=1 to 10000 by 1 j=random(1,100) histogram.j=histogram.j+1 end do i=1 to 100 by 1 say "f(" || i || ") = " || histogram.i end --------------------------- Running tstrand.rexx gives the following distribution: (10000 data points, broken into 100 intervals, should yield 100 per interval for a perfectly uniform distribution.) f(1) = 93 f(2) = 109 f(3) = 96 f(4) = 115 f(5) = 123 f(6) = 103 f(7) = 91 f(8) = 97 f(9) = 94 f(10) = 96 f(11) = 113 f(12) = 89 f(13) = 113 f(14) = 104 f(15) = 104 f(16) = 102 f(17) = 93 f(18) = 104 f(19) = 121 f(20) = 103 f(21) = 89 f(22) = 99 f(23) = 102 f(24) = 96 f(25) = 97 f(26) = 95 f(27) = 102 f(28) = 86 f(29) = 88 f(30) = 93 f(31) = 102 f(32) = 93 f(33) = 111 f(34) = 114 f(35) = 101 f(36) = 109 f(37) = 81 f(38) = 97 f(39) = 109 f(40) = 92 f(41) = 104 f(42) = 88 f(43) = 106 f(44) = 116 f(45) = 93 f(46) = 101 f(47) = 122 f(48) = 117 f(49) = 96 f(50) = 107 f(51) = 86 f(52) = 111 f(53) = 101 f(54) = 103 f(55) = 115 f(56) = 101 f(57) = 106 f(58) = 105 f(59) = 98 f(60) = 83 f(61) = 95 f(62) = 106 f(63) = 95 f(64) = 108 f(65) = 87 f(66) = 101 f(67) = 88 f(68) = 117 f(69) = 91 f(70) = 92 f(71) = 109 f(72) = 98 f(73) = 73 f(74) = 108 f(75) = 105 f(76) = 91 f(77) = 123 f(78) = 96 f(79) = 87 f(80) = 97 f(81) = 94 f(82) = 101 f(83) = 100 f(84) = 98 f(85) = 103 f(86) = 84 f(87) = 98 f(88) = 104 f(89) = 92 f(90) = 104 f(91) = 97 f(92) = 121 f(93) = 89 f(94) = 109 f(95) = 98 f(96) = 102 f(97) = 79 f(98) = 97 f(99) = 100 f(100) = 85 As you can see, all frequencies are fairly close to 100. I won't bother doing a detailed analysis of this, because a glance tells me that random() has been improved from version 1.06. This same test under 1.06 gave me entire blocks (5 or 6 units) of 0 or 1 occurrence, and entire blocks of 200-300 occurrences. It was that bad. So, it looks like I can dump my rxandom() function and use my original version (or Larry's modification). -- --------------------------------------- Eric Kennedy eric@eklektik.pgh.pa.us (formerly ejkst@pitt.UUCP) ...pitt!idis!eklektik!eric