seanc@pro-party.cts.com (Sean Cunningham) (08/01/90)
I need someone who's skilled at writing nifty batch programs out there to tell me if what I'm wanting to do is possible...and if it is, maybe some insight on how to do it... I'd like to setup my startup-sequence to play a sample when I boot-up, but I don't want it to be the same one everytime. I figured I could make a directory with ten sounds numbered from 0 to 9, and then for the randomness, look at whatever value is in the second's place on my internal clock. Is it possible to do this??? thanx in advance...Sean //////////////////////////////////////////////////////////////////////////// UUCP: ...!crash!pnet01!pro-party!seanc | ARPA: !crash!pnet01!pro-party!seanc@nosc.mil | " Fanatics have their INET: seanc@pro-party.cts.com | dreams, wherewith they | weave a paradise for RealWorld: Sean Cunningham | a sect. " Voice: (512) 994-1602 PLINK: ce3k* | -Keats | Call C.B.A.U.G. BBS (512) 883-8351 w/SkyPix | B^) VISION GRAPHICS B^) \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
eric@eklektik.UUCP (/dev/tty000) (08/01/90)
In article <3769@crash.cts.com> seanc@pro-party.cts.com (Sean Cunningham) writes: >I'd like to setup my startup-sequence to play a sample when I boot-up, but I >don't want it to be the same one everytime. I figured I could make a >directory with ten sounds numbered from 0 to 9, and then for the randomness, >look at whatever value is in the second's place on my internal clock. I've done a similar thing in my startup using ARexx and Joe Hitchens' nifty Tapestry program. This randomly chooses a picture out of my s:pix directory and installs it as a backdrop picture. Basically, all it does is do a directory of s:pix, counts the files, choose one randomly, then call tapestry. The complete script is here. (Most of it is a custom random function, rxandom(), since ARexx's builtin random function kept giving me the same pictures...) ------------- Cut Here -------------- /* Tapestry.rexx -- Randomly choose a picture file for tapestry to display */ files = showdir("s:pix") RandomSeed=1000*time('S') address command "run tapestry s:pix/"||word(files,rxandom(1,words(files))) exit rxandom: arg rmin,rmax ARAND = 16807 MRAND = 2147483647 QRAND = 127773 RRAND = 2836 hi = RandomSeed%QRAND lo = RandomSeed//QRAND test = ARAND*lo + RRAND*hi if test>0 then RandomSeed = test else RandomSeed=test+MRAND r=min(rmax,((RandomSeed/2175506758)*(rmax-rmin+1)%1)+rmin) return r ------------- Cut Here -------------- -- --------------------------------------- Eric Kennedy eric@eklektik.pgh.pa.us (formerly ejkst@pitt.UUCP) ...pitt!idis!eklektik!eric
lphillips@lpami.wimsey.bc.ca (Larry Phillips) (08/03/90)
In <4933@eklektik.UUCP>, eric@eklektik.UUCP (/dev/tty000) writes: > >I've done a similar thing in my startup using ARexx and Joe Hitchens' nifty >Tapestry program. This randomly chooses a picture out of my s:pix directory >and installs it as a backdrop picture. Basically, all it does is do a >directory of s:pix, counts the files, choose one randomly, then call tapestry. >The complete script is here. (Most of it is a custom random function, >rxandom(), since ARexx's builtin random function kept giving me the same >pictures...) The seed for the Arexx random number generator is initialized to a particular value when it is loaded, and started from the same seed, random() will always produce the same initial value, and from that, seed the random number generator 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 within your application to suit the purpose. Here's your program, modified. ------------- Cut Here -------------- /* 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 >------------- Cut Here -------------- -larry -- Sex is better than logic, but I can't prove it. +-----------------------------------------------------------------------+ | // Larry Phillips | | \X/ lphillips@lpami.wimsey.bc.ca -or- uunet!van-bc!lpami!lphillips | | COMPUSERVE: 76703,4322 -or- 76703.4322@compuserve.com | +-----------------------------------------------------------------------+
eric@eklektik.UUCP (/dev/tty000) (08/07/90)
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