> >--- Larry Wall <[EMAIL PROTECTED]> wrote: > >> The hard part being to pick a random number in [0,Inf) uniformly. :-) > > > >Half of all numbers in [0, Inf) are in the range [Inf/2, Inf). Which > >collapses to the range [Inf, Inf). Returning Inf seems to satisfy the > >uniform distribution requirement: if you have a number you're waiting > >to see returned, just wait a bit longer... > > I like the 1/n trick used in the Perl Cookbook (Picking a Random Line from > a File). We could apply the same idea here: > > rand($_)<1 && ($chosen=$_) for 1...Inf; I don't believe that that could give you an value ...
> All right, it would take a bit longer for your program to run, but that's > a performance issue for them to sort out on *-internals. Like, it would take a bit longer than your lifetime :-)? > -David "sure Moore's Law will deal with it in a year or two" Green 'And my new '986 does the infinite loop in under 3.5 seconds' :-) To repeat Dave and myself - if @x = 1 .. Inf; then rand(@x) should be Inf, and so print $x[rand(@x)]; should give Inf, as the infinite element of @x is Inf. But maybe we could get an index of Inf working like -1 (ie. the last value): @x = 1 .. Inf; push @x, "a"; print $x[Inf]; would print an "a" ... although, on this line of reasoning, print $x[rand(@x)]; would always print "a" .... I believe that an array should get an .rand-Method, which could do the right thing. @x= (1 .. Inf, "b", -Inf .. -1, "c", 1 .. Inf); print $x[rand(@x)],"\n" while (1); could give Inf Inf -Inf b c Inf -Inf and so on - an "random" element of a random part of the array, and an infinite list gives Inf (or -Inf) as a random element (as explained above in this thread). So an array would have to know of how many "pieces" it is constructed, and then choose an element among the pieces ... I'd think that's reasonable, isn't it? Regards, Phil