From: Peter J. Holzer on 1 Jun 2010 08:18 On 2010-06-01 08:50, Uri Guttman <uri(a)StemSystems.com> wrote: >>>>>> "PY" == Peng Yu <pengyu.ut(a)gmail.com> writes: > PY> On Jun 1, 12:03�am, "Uri Guttman" <u...(a)StemSystems.com> wrote: > >> � JE> Ok. For those like me not familiar with this term: he means random > >> � JE> numbers with and without repetition. > >> > >> and i told him how to do it. i won't tell him again. it is a simple > >> problem and hashes solve it. > > PY> What do you mean? I didn't ask you to tell me again. > > i told you how to do it. either you didn't read it or you didn't get the > solution. Uri, nobody asked you to tell him again. Why do insist on telling us three times that you won't do it? Nobody asked me to write a haiku, but I don't feel the slightest urge to tell you all that I won't write a haiku, hp
From: J�rgen Exner on 1 Jun 2010 08:46 Peng Yu <pengyu.ut(a)gmail.com> wrote: >On Jun 1, 12:03�am, "Uri Guttman" <u...(a)StemSystems.com> wrote: >> >>>>> "JE" == J�rgen Exner <jurge...(a)hotmail.com> writes: >> >> � JE> Peng Yu <pengyu...(a)gmail.com> wrote: >> � >> On May 31, 10:25�pm, J�rgen Exner <jurge...(a)hotmail.com> wrote: >> � >>> Peng Yu <pengyu...(a)gmail.com> wrote: >> � >>> >It seems that the int(rand(10)) generate random with replacement. I'm >> � >>> >wondering how to generate random number without replacement in perl. >> � >>> >> � >>> Could you please explain what you mean by "with/without replacement"? >> � >>> A number is a number, it doesn't replace anything.... >> � >> >> � >> These are standard concepts in statistics. Please see the following >> � >> webpage for the explanations on sampling 'with/without replacement'. >> � >> >> � >>http://www.ma.utexas.edu/users/parker/sampling/repl.htm >> >> � JE> Ok. For those like me not familiar with this term: he means random >> � JE> numbers with and without repetition. > >But I feel sorry that perl doesn't provide such a function out of the >box. I feel neither sorry nor that Perl should provide such a function. You are confusing generating random numbers with sampling a given data set. Now, you could argue that beside equal distribution Perl should also provide additional distributions of random numbers like e.g. Gaussian distributions or random number without repetition or any other distribution. However IMNSHO Perl is a general purpose programming language and functions like that are WAAAAYYYY to subject matter specific. If you want them, then put them in a module. And of course you very welcome to submit such a module to CPAN. jue
From: Ted Zlatanov on 1 Jun 2010 14:18 On Tue, 01 Jun 2010 04:50:36 -0400 "Uri Guttman" <uri(a)StemSystems.com> wrote: UG> my %seen ; UG> while( 1 ) { $x = int rand( 100_000_000 ) ; $seen{$x} and next ; UG> $seen{$x} = 1; print $x } This will grow pretty quickly with a hash. Bit::Vector already has Bit_On($index) and bit_test($index) so memory usage and probably performance will be a bit (heh) better. Ted
From: Uri Guttman on 1 Jun 2010 15:37 >>>>> "TZ" == Ted Zlatanov <tzz(a)lifelogs.com> writes: TZ> On Tue, 01 Jun 2010 04:50:36 -0400 "Uri Guttman" <uri(a)StemSystems.com> wrote: UG> my %seen ; UG> while( 1 ) { $x = int rand( 100_000_000 ) ; $seen{$x} and next ; UG> $seen{$x} = 1; print $x } TZ> This will grow pretty quickly with a hash. Bit::Vector already has TZ> Bit_On($index) and bit_test($index) so memory usage and probably TZ> performance will be a bit (heh) better. he said he wanted 1k random numbers out of a large range so a hash would be fine for that. uri -- Uri Guttman ------ uri(a)stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
From: Xho Jingleheimerschmidt on 1 Jun 2010 23:54 Ted Zlatanov wrote: > On Tue, 01 Jun 2010 04:50:36 -0400 "Uri Guttman" <uri(a)StemSystems.com> wrote: > > UG> my %seen ; > UG> while( 1 ) { $x = int rand( 100_000_000 ) ; $seen{$x} and next ; > UG> $seen{$x} = 1; print $x } > > This will grow pretty quickly with a hash. Bit::Vector already has > Bit_On($index) and bit_test($index) so memory usage and probably > performance will be a bit (heh) better. I'd be very surprised if Bit::Vector had faster performance, at least until the other method started swapping. Xho
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 5 Prev: Troubles using Net::Pcap and Net::PcapUtils Next: How to take two input streams? |