Re: Random #'s
Hi Dwane, I am using the following code to generate a field of 6 random numbers. repeat 5 times --generate list of 5 random numbers between 1-10 put random(10) , after tRnum end repeat delete last char of tRnum --delete last comma put tRnum into fld numbers this works fine but some numbers are repeated in the field, e.g (1,2,3,1,5) How can I include only unique numbers? function uniqueRandomNumberList listEntryCount, maxListNumber -- You would pass 5,10 if listEntryCount 1 then return empty put empty into numberList put empty into returnValue repeat with x = 1 to maxListNumber put xreturn after numberList end repeat repeat get the random of maxListNumber put line it of numberList after returnValue delete line it of numberList subtract 1 from listEntryCount if listEntryCount 1 then return returnValue put comma after returnValue subtract 1 from maxListNumber end repeat end uniqueRandomNumberList ___ use-revolution mailing list use-revolution@lists.runrev.com http://lists.runrev.com/mailman/listinfo/use-revolution
Re: Random #s
If you are asking the random of a big number then that will be true. I think I remember that to generate a list of random numbers what you should be doing is asking questions like random(N) random(N-1) . . . 1 If you wanted to generate a random list with the numbers 1 thru 10 random(10) - 3 Now you pick the 3rd item of the list of integers{1,2,3,4,5,6,7,8,9,10} you pick 3 and remove the 3rd item. Your random list is {3} random(9)-3 Now you pick the 3rd item of the remaining integers {1,2,4,5,6,7,8,9,10}: you pick 4 and remove the 3rd item. Your random list is {3,4} And so on. Michael On Jan 27, 2005, at 7:35 AM, Dave Cragg wrote: Although I'm sure this is fine in practice, this kind of solution always makes me a little nervous. In theory, it could take for ever to find a unique set of numbers. While my testing shows it never takes longer than a millisecond, Murphy's law says that the first time you put it into an application, it will take three days. :) ___ use-revolution mailing list use-revolution@lists.runrev.com http://lists.runrev.com/mailman/listinfo/use-revolution
Re: Random #'s
What does it mean to sort 1,2,3,4,5 by 12? Maybe it should be sort items of x numeric by random(1) ? Michael On Jan 27, 2005, at 4:21 PM, Dar Scott wrote: On Jan 27, 2005, at 2:31 AM, D.Rothe wrote: How can I include only unique numbers? Here is an interesting variation: on mouseUp put rlist() end mouseUp function rlist put 1,2,3,4,5,6,7,8,9,10 into x sort items of x by random(1) return item 1 to 6 of x end rlist Dar ** DSC (Dar Scott Consulting Dar's Lab) http://www.swcp.com/dsc/ Programming Services and Software ** ___ use-revolution mailing list use-revolution@lists.runrev.com http://lists.runrev.com/mailman/listinfo/use-revolution ___ use-revolution mailing list use-revolution@lists.runrev.com http://lists.runrev.com/mailman/listinfo/use-revolution
Re: Random #'s
On Jan 28, 2005, at 11:08 AM, Michael D Mays wrote: What does it mean to sort 1,2,3,4,5 by 12? Maybe it should be sort items of x numeric by random(1) Yes! Sorry about that. I think sort by 12 effectively means to associate 12 with each item and then sort by the associated value. The sort by random(1) would then mean to associate a random value with each item and sort by that. The sort by char -1 or each would associate the last char of each item with the item and sort by that. I don't know if it actually implemented that way; it might be the sorting expression is evaluated repeatedly with each comparison. Maybe one can run a test with a side effect (say counting) to find out. Dar ** DSC (Dar Scott Consulting Dar's Lab) http://www.swcp.com/dsc/ Programming Services and Software ** ___ use-revolution mailing list use-revolution@lists.runrev.com http://lists.runrev.com/mailman/listinfo/use-revolution
Re: Random #'s
Hey Guys after analysing the multitude of responses I finally went with the shortest code! It works perfect fast, thats all I needed repeat until the number of items in tRnum = 5 set randomSeed to random(1) put random(10) into tRand if tRand is not among the items of tRnum then put tRand comma after tRnum end repeat Thanx to all... Dwayne On Jan 28, 2005, at 11:08 AM, Michael D Mays wrote: What does it mean to sort 1,2,3,4,5 by 12? Maybe it should be sort items of x numeric by random(1) Yes! Sorry about that. I think sort by 12 effectively means to associate 12 with each item and then sort by the associated value. The sort by random(1) would then mean to associate a random value with each item and sort by that. The sort by char -1 or each would associate the last char of each item with the item and sort by that. I don't know if it actually implemented that way; it might be the sorting expression is evaluated repeatedly with each comparison. Maybe one can run a test with a side effect (say counting) to find out. Dar ** ___ use-revolution mailing list use-revolution@lists.runrev.com http://lists.runrev.com/mailman/listinfo/use-revolution
Random #'s
Hi All, I am using the following code to generate a field of 6 random numbers. repeat 5 times --generate list of 5 random numbers between 1-10 put random(10) , after tRnum end repeat delete last char of tRnum --delete last comma put tRnum into fld numbers this works fine but some numbers are repeated in the field, e.g (1,2,3,1,5) How can I include only unique numbers? Cheers..Dwayne ___ use-revolution mailing list use-revolution@lists.runrev.com http://lists.runrev.com/mailman/listinfo/use-revolution
Re: Random #'s
Here's one way to do it, with a button-script: (B (Bon mouseUp (B repeat (Bif the number of lines in tResult 5 then exit repeat (Bput random(10) into tRand (Bif tRand is not among the lines of tResult then (B put tRand cr after tResult (Bend if (B end repeat (B delete the last char of tResult (B replace cr with comma in tResult (B put tResult into field "fNumbers" (Bend mouseUp (B (BCheers, (BNicolas Cueto (Bniconiko language school (B(Japan) (B___ (Buse-revolution mailing list (Buse-revolution@lists.runrev.com (Bhttp://lists.runrev.com/mailman/listinfo/use-revolution
Re: Random #s
How about something like: repeat until the number of items in tRnum = 5 put random(10) into tRand if tRand is not among the items of tRnum then put tRand comma after tRnum end repeat Cheers, Mark On 27 Jan 2005, at 10:34, [EMAIL PROTECTED] wrote: repeat 5 times --generate list of 5 random numbers between 1-10 put random(10) , after tRnum end repeat delete last char of tRnum --delete last comma put tRnum into fld numbers ___ use-revolution mailing list use-revolution@lists.runrev.com http://lists.runrev.com/mailman/listinfo/use-revolution
Re: Random #'s
Hi All, I am using the following code to generate a field of 6 random numbers. repeat 5 times --generate list of 5 random numbers between 1-10 put random(10) , after tRnum end repeat delete last char of tRnum --delete last comma put tRnum into fld numbers this works fine but some numbers are repeated in the field, e.g (1,2,3,1,5) How can I include only unique numbers? Cheers..Dwayne Hmmm. put 1,2,3,4,5,6,7,8,9,10 into tlist repeat with i = 10 down to 6 put random(i) into x put item x of tlist into item(i - 9) of tRnum delete item x of tlist end repeat put tRnum into fld numbers OR put 1,2,3,4,5,6,7,8,9,10 into tlist sort items of tlist by random(100) put item 1 to 6 of tlist into fld numbers Regards, Raymond ___ use-revolution mailing list use-revolution@lists.runrev.com http://lists.runrev.com/mailman/listinfo/use-revolution ___ use-revolution mailing list use-revolution@lists.runrev.com http://lists.runrev.com/mailman/listinfo/use-revolution
Re: Random #s
On 27 Jan 2005, at 11:25, Mark Smith wrote: How about something like: repeat until the number of items in tRnum = 5 put random(10) into tRand if tRand is not among the items of tRnum then put tRand comma after tRnum end repeat Although I'm sure this is fine in practice, this kind of solution always makes me a little nervous. In theory, it could take for ever to find a unique set of numbers. While my testing shows it never takes longer than a millisecond, Murphy's law says that the first time you put it into an application, it will take three days. :) For the nervous ninnies like myself, this function should be more consistent: function any5from10 put 1,2,3,4,5,6,7,8,9,10 into tList sort items of tList by random(1000) return item 1 to 5 of tList end any5from10 Cheers Dave ___ use-revolution mailing list use-revolution@lists.runrev.com http://lists.runrev.com/mailman/listinfo/use-revolution
Re: Random #'s
Hi Dwayne, put GenerateRandom(6,10) -- the right parameters in your case function GenerateRandom pHowMuchNumbers,pRange local tRangeList - repeat until the number of lines of tRangeList = pHowMuchNumbers set the randomSeed to random(10) put random(pRange) into pNum if pNum is not among the lines of tRangeList then put pNum cr after tRangeList end repeat delete char -1 of tRangeList return tRangeList end GenerateRandom Hope this helps. Le 27 janv. 05, à 11:34, D.Rothe [EMAIL PROTECTED] a écrit : Hi All, I am using the following code to generate a field of 6 random numbers. repeat 5 times --generate list of 5 random numbers between 1-10 put random(10) , after tRnum end repeat delete last char of tRnum --delete last comma put tRnum into fld numbers this works fine but some numbers are repeated in the field, e.g (1,2,3,1,5) How can I include only unique numbers? Cheers..Dwayne Amicalement, Éric Chatonet 24, Boulevard de Port-Royal 75005 Paris Fixe : 33 1 43 31 77 62 Mobile :33 6 20 74 50 89 ___ use-revolution mailing list use-revolution@lists.runrev.com http://lists.runrev.com/mailman/listinfo/use-revolution
Re: Random #'s
Dwayne, I'm sure there's a better way to do it, but how about this... function makeRandomNumberList maxNumber put 0 into i repeat put random(10) into thisNum if thisNum is among the items of fNumbers then next repeat end if add 1 to i put thisNum into item i of fNumbers if i = 6 then exit repeat end if end repeat return fNumbers end makeRandomNumberList Hi All, I am using the following code to generate a field of 6 random numbers. repeat 5 times --generate list of 5 random numbers between 1-10 put random(10) , after tRnum end repeat delete last char of tRnum --delete last comma put tRnum into fld numbers this works fine but some numbers are repeated in the field, e.g (1,2,3,1,5) How can I include only unique numbers? Cheers..Dwayne ___ use-revolution mailing list use-revolution@lists.runrev.com http://lists.runrev.com/mailman/listinfo/use-revolution
Re: Random #'s
On Jan 27, 2005, at 2:31 AM, D.Rothe wrote: How can I include only unique numbers? Here is an interesting variation: on mouseUp put rlist() end mouseUp function rlist put 1,2,3,4,5,6,7,8,9,10 into x sort items of x by random(1) return item 1 to 6 of x end rlist Dar ** DSC (Dar Scott Consulting Dar's Lab) http://www.swcp.com/dsc/ Programming Services and Software ** ___ use-revolution mailing list use-revolution@lists.runrev.com http://lists.runrev.com/mailman/listinfo/use-revolution
Re: Random #'s
Message: 17 Date: Thu, 27 Jan 2005 15:21:09 -0700 From: Dar Scott [EMAIL PROTECTED] Subject: Re: Random #'s To: How to use Revolution use-revolution@lists.runrev.com Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=US-ASCII; format=flowed On Jan 27, 2005, at 2:31 AM, D.Rothe wrote: How can I include only unique numbers? Here is an interesting variation: on mouseUp put rlist() end mouseUp function rlist put 1,2,3,4,5,6,7,8,9,10 into x sort items of x by random(1) return item 1 to 6 of x end rlist Dar I confess, I never understood this. And I can't imagine how Dwayne will choose among the multitude of solutions proposed. Maybe: put all solutions into x sort items of all ten solutions by random(1) return item 1 of x Jim ___ use-revolution mailing list use-revolution@lists.runrev.com http://lists.runrev.com/mailman/listinfo/use-revolution