Re: AW: AW: How do I pick one random element from an array?

2009-11-03 Thread Uri Guttman
> >> Just like $array[ int(0.7995038473872) ], i.e. the floating point >> number is coerced into an integer value by cutting off the decimal >> places. DT> Ah cool. So when using rand in this aspect (i.e. getting random DT> indexes from an array), the int is neglig

Re: How do I pick one random element from an array?

2009-11-03 Thread John W. Krahn
to append each new scalar value onto the array: push @lines, $_; Or you could just assign the whole file in one go: my @lines = ; print "$lines[rand @lines]"; } __DATA__ uriel daniel joel samue It would not display the random element of the array Why ? Or if I want to display

Re: How do I pick one random element from an array?

2009-11-03 Thread John W. Krahn
bin/perl -w use strict; use List::Util 'shuffle'; my @array = ('uriel', 'daniel', 'joel', 'samuel'); print "Array before random: @array\n\n"; print "Array of random: $array[rand @array]\n"; @array = shuffle @array; print

Re: How do I pick one random element from an array?

2009-11-03 Thread Majian
Thanks all . But I found an another question : If I wrote this script like this : #!/usr/bin/perl while (){ @lines = $_; print "$lines[rand @lines]"; } __DATA__ uriel daniel joel samue It would not display the random element of the array Why ? Or if I want to display the random

Re: How do I pick one random element from an array?

2009-11-03 Thread tom smith
; > > Now what I want is create a process so every time I print the array it > prints one element from the array . > > I wrote it like this : > > #!/usr/bin/perl -w > > use strict; > > my @array = ('uriel', 'daniel', 'joel', 'samue

Re: How do I pick one random element from an array?

2009-11-03 Thread Philip Potter
I wrote it like this : >> >> #!/usr/bin/perl -w >> >> use strict; > > use List::Util 'shuffle'; > > >> my @array = ('uriel', 'daniel', 'joel', 'samuel'); >> print "Array before random: @array\

Re: AW: AW: How do I pick one random element from an array?

2009-11-03 Thread Dave Tang
decimal places. Ah cool. So when using rand in this aspect (i.e. getting random indexes from an array), the int is negligible? Thanks Thomas! Cheers, Dave HTH, Thomas -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ -- To unsubscribe, e-mail: begi

Re: How do I pick one random element from an array?

2009-11-03 Thread John W. Krahn
he array it prints one element from the array . I wrote it like this : #!/usr/bin/perl -w use strict; use List::Util 'shuffle'; my @array = ('uriel', 'daniel', 'joel', 'samuel'); print "Array before random: @array\n\n"; print &quo

AW: AW: How do I pick one random element from an array?

2009-11-02 Thread Thomas Bätzler
Dave Tang asked: > Just a quick question, how does Perl interpret something like > $array[0.7995038473872]? Just like $array[ int(0.7995038473872) ], i.e. the floating point number is coerced into an integer value by cutting off the decimal places. HTH, Thomas -- To unsubscribe, e-mail: beginn

Re: AW: How do I pick one random element from an array?

2009-11-02 Thread Dave Tang
On Tue, 03 Nov 2009 17:23:38 +1000, Thomas Bätzler wrote: Majian asked: [...] print "Array of random: $array[rand @array]\n"; I thoght it might work but it doesnt. I hope someone could give me an idea to work this out... TIMTOWTDY: a) print "Array of random: $arr

AW: How do I pick one random element from an array?

2009-11-02 Thread Thomas Bätzler
Majian asked: [...] > print "Array of random: $array[rand @array]\n"; > > > I thoght it might work but it doesnt. I hope someone could give me an > idea to work this out... TIMTOWTDY: a) print "Array of random: $array[rand( @array ) ] \n"; b) print "

How do I pick one random element from an array?

2009-11-02 Thread Majian
lement from the array . I wrote it like this : #!/usr/bin/perl -w use strict; my @array = ('uriel', 'daniel', 'joel', 'samuel'); print "Array before random: @array\n\n"; print "Array of random: $array[rand @array]\n"; I thoght it might work but it doesnt. I hope someone could give me an idea to work this out...

Re: Random number generator

2009-04-09 Thread ANJAN PURKAYASTHA
Thank you guys. Anjan On Thu, Apr 9, 2009 at 6:59 PM, Chas. Owens wrote: > On Thu, Apr 9, 2009 at 17:34, ANJAN PURKAYASTHA > wrote: > > I need a Bernoulli random number generator which takes as inputs: a value > > for p(1) (probability of choosing a "1")

Re: Random number generator

2009-04-09 Thread Chas. Owens
On Thu, Apr 9, 2009 at 17:34, ANJAN PURKAYASTHA wrote: > I need a Bernoulli random number generator which takes as inputs: a value > for p(1) (probability of choosing a "1") and the number of trials and > outputs a series of 0s and 1s according to the model B(p(1)). > Any th

Re: Random number generator

2009-04-09 Thread Jim Gibson
On 4/9/09 Thu Apr 9, 2009 2:34 PM, "ANJAN PURKAYASTHA" scribbled: > I need a Bernoulli random number generator which takes as inputs: a value > for p(1) (probability of choosing a "1") and the number of trials and > outputs a series of 0s and 1s according to the

Random number generator

2009-04-09 Thread ANJAN PURKAYASTHA
I need a Bernoulli random number generator which takes as inputs: a value for p(1) (probability of choosing a "1") and the number of trials and outputs a series of 0s and 1s according to the model B(p(1)). Any thoughts on which module I need to use?

Re: problem with random arrays

2009-03-12 Thread John W. Krahn
Kammen van, Marco, Springer SBM NL wrote: Hi All, Hello, I'm trying to generate random sentences using a few words, but can't get the thing to work.. I know I'm doing something wrong but what? :-D Any help is appreciated! #!/usr/bin/perl -w #!/usr/bin/perl use warni

Re: problem with random arrays

2009-03-12 Thread Chas. Owens
On Thu, Mar 12, 2009 at 03:40, Kammen van, Marco, Springer SBM NL wrote: > Hi All, > > > > I'm trying to generate random sentences using a few words, but can't get > the thing to work.. > > I know I'm doing something wrong but what? :-D > > > &

problem with random arrays

2009-03-12 Thread Kammen van, Marco, Springer SBM NL
Hi All, I'm trying to generate random sentences using a few words, but can't get the thing to work.. I know I'm doing something wrong but what? :-D Any help is appreciated! #!/usr/bin/perl -w # my $count = "0"; my $word0 = "aap&quo

Re: self centering random walk within defined range

2009-03-01 Thread Rob Canning
Chas. Owens said : > On Sat, Feb 28, 2009 at 14:56, Chas. Owens wrote: > snip > > This seems close to what you want, but it needs work to make it take > > steps larger than 1: > snip > > Here is another version that takes steps larger than one: > > #!/usr/bin/perl > > use strict; > use warnings

Re: self centering random walk within defined range

2009-02-28 Thread Chas. Owens
On Sat, Feb 28, 2009 at 14:56, Chas. Owens wrote: snip > This seems close to what you want, but it needs work to make it take > steps larger than 1: snip Here is another version that takes steps larger than one: #!/usr/bin/perl use strict; use warnings; # 12345678901 # * # 5/11 chance of

Re: self centering random walk within defined range

2009-02-28 Thread Chas. Owens
> while ($t==1){ >> > >> > my $rndi  = $intervalset[rand @intervalset]; >> > >> > $current = ($rndi+$current); >> > >> > print $current,"\n"; >> > >> > } >> >> You are falling for the fabled &#x

Re: self centering random walk within defined range

2009-02-28 Thread rob
> > > my @intervalset = qw(1 2 -1 -2); > > > > my $current = 0; > > > > my $t = 1; > > > > while ($t==1){ > > > > my $rndi = $intervalset[rand @intervalset]; > > > > $current = ($rndi+$current); > > > > print $cu

Re: self centering random walk within defined range

2009-02-28 Thread Rob Dixon
d @intervalset]; > > $current = ($rndi+$current); > > print $current,"\n"; > > } You are falling for the fabled 'law of averages' that tells people they are more likely to win the lottery after losing many times. The sum will not hover around its starti

self centering random walk within defined range

2009-02-28 Thread rob
hi, i am finding something couter intuative about randomness and search for a solution. i have a bit of code that randomly selects a number from an array and then adds it to the previous number. I have two positive numbers and their negitives qw(1 2 -1 -2) i expected the below code to hover

Re: One liner to generate truly random passwords from command line

2008-11-28 Thread Chas. Owens
On Fri, Nov 28, 2008 at 22:21, John W. Krahn <[EMAIL PROTECTED]> wrote: > Chas. Owens wrote: >> >> On Fri, Nov 28, 2008 at 10:28, John W. Krahn <[EMAIL PROTECTED]> wrote: >> snip >>> >>> perl -le'@chars = 33 .. 126; print map chr $chars[ rand @chars ], 1 .. 8' >> >> snip >> >> Perl Golf time: >> >>

Re: One liner to generate truly random passwords from command line

2008-11-28 Thread John W. Krahn
Chas. Owens wrote: On Fri, Nov 28, 2008 at 10:28, John W. Krahn <[EMAIL PROTECTED]> wrote: snip perl -le'@chars = 33 .. 126; print map chr $chars[ rand @chars ], 1 .. 8' snip Perl Golf time: perl -le'print map chr+(33..126)[rand 94],1..8' $ perl -le'print map chr+(33..126)[rand 94],1..8' Wa

Re: One liner to generate truly random passwords from command line

2008-11-28 Thread Chas. Owens
On Fri, Nov 28, 2008 at 10:28, John W. Krahn <[EMAIL PROTECTED]> wrote: snip > perl -le'@chars = 33 .. 126; print map chr $chars[ rand @chars ], 1 .. 8' snip Perl Golf time: perl -le'print map chr+(33..126)[rand 94],1..8' -- Chas. Owens wonkden.net The most important skill a programmer can have

Re: One liner to generate truly random passwords from command line

2008-11-28 Thread Chas. Owens
"\n"' > > wget reads web pages > random.org generates random numbers using atmospheric noise > perl splits the input into tokens and converts Except you have transmitted your random number in cleartext over the net. As an attacker, I could be sniffing for http traffic (

Re: One liner to generate truly random passwords from command line

2008-11-28 Thread John W. Krahn
Yimin Rong wrote: wget -q -O - "http://random.org/integers/? num=8&min=33&max=126&col=8&base=16&format=plain&rnd=new" | perl -ne 'foreach (split(/\t/, $_)) {print chr(hex($_));} print "\n"' You can simplify the perl part to: perl -lane'print map chr hex, @F' Or just using perl: perl -MLWP::

One liner to generate truly random passwords from command line

2008-11-28 Thread Yimin Rong
wget -q -O - "http://random.org/integers/? num=8&min=33&max=126&col=8&base=16&format=plain&rnd=new" | perl -ne 'foreach (split(/\t/, $_)) {print chr(hex($_));} print "\n"' wget reads web pages random.org generates random numbers using a

Re: random

2008-11-25 Thread Mr. Shawn H. Corey
On Tue, 2008-11-25 at 12:51 -0500, Telemachus wrote: > On Tue Nov 25 2008 @ 12:45, Telemachus wrote: > > If you want to check if you something Perl-ish > > Something clearly went wrong here. I got caught between "to check if you can > do something with Perl" and "to check something Perl-ish." Wha

Re: random

2008-11-25 Thread Telemachus
On Tue Nov 25 2008 @ 12:45, Telemachus wrote: > If you want to check if you something Perl-ish Something clearly went wrong here. I got caught between "to check if you can do something with Perl" and "to check something Perl-ish." What I sent was neither. Feh. -- To unsubscribe, e-mail: [EMAIL

Re: random

2008-11-25 Thread Telemachus
On Tue Nov 25 2008 @ 9:29, Sharan Basappa wrote: > Hi, > > Would like to know if perl has native (without using special modules) > for generating random numbers? Shawn already pointed you in the right direction, but here's a good tip. If you want to check if you something Perl-

Re: random

2008-11-25 Thread Mr. Shawn H. Corey
On Tue, 2008-11-25 at 21:29 +0530, Sharan Basappa wrote: > Hi, > > Would like to know if perl has native (without using special modules) > for generating random numbers? > > Regards > See `perldoc -f rand`. -- Just my 0.0002 million dollars worth, Shawn The ke

random

2008-11-25 Thread Sharan Basappa
Hi, Would like to know if perl has native (without using special modules) for generating random numbers? Regards -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: how to produce random dates

2008-09-21 Thread John W. Krahn
itshardtogetone wrote: - Original Message - From: "John W. Krahn" <[EMAIL PROTECTED]> use Time::Local; my $start = timegm 0,0,0,1,0,60; my $end = timegm 0,0,0,1,0,86; print scalar gmtime $start + rand $end - $start; Hi, Thanks. (1) But the above from time to time produce the fol

Re: how to produce random dates

2008-09-21 Thread John W. Krahn
Mr. Shawn H. Corey wrote: On Sat, 2008-09-20 at 03:53 -0700, John W. Krahn wrote: itshardtogetone wrote: Hi, Hello, How do I randomly produce a date between 1st Jan 1960 to 31th December 1985. It must be able to show the day month year. I only know how to produce a random number between

Re: how to produce random dates

2008-09-20 Thread Mr. Shawn H. Corey
On Sat, 2008-09-20 at 03:53 -0700, John W. Krahn wrote: > itshardtogetone wrote: > > Hi, > > Hello, > > > How do I randomly produce a date between 1st Jan 1960 to 31th December > > 1985. It must be able to show the day month year. > > I only know how to pro

Re: how to produce random dates

2008-09-20 Thread John W. Krahn
itshardtogetone wrote: Hi, Hello, How do I randomly produce a date between 1st Jan 1960 to 31th December 1985. It must be able to show the day month year. I only know how to produce a random number between 1960 to 1985 using rand like this : my $year = int (rand 26) + 1960; use Time

how to produce random dates

2008-09-20 Thread itshardtogetone
Hi, How do I randomly produce a date between 1st Jan 1960 to 31th December 1985. It must be able to show the day month year. I only know how to produce a random number between 1960 to 1985 using rand like this : my $year = int (rand 26) + 1960; Thanks

Re: Random Image and Cache problem

2007-09-03 Thread Dr.Ruud
Carl Miller schreef: > The other website would call the perl script in an tag, like so: > > http://www.my_site.com/cgi-bin/random_banner.cgi"; > width="468" height="60"> > > I've tried several perl scripts that basically work, but the problem > is always the same with all of them: the browser alw

Re: Random Image and Cache problem

2007-09-03 Thread Mumia W.
On 09/03/2007 10:06 AM, Carl Miller wrote: Thanks Gunnar and Mumia. I figured out that the problem is unique to Internet Explorer. The three other browsers I tried don't have this problem. But I can't get IE to not cache. I've tried these: print "Cache-Control: no-cache\n"; print "Pr

Re: Random Image and Cache problem

2007-09-03 Thread Tom Phoenix
On 9/3/07, Carl Miller <[EMAIL PROTECTED]> wrote: > I figured out that the problem is unique to Internet Explorer. The three > other browsers I tried don't have this problem. But I can't get IE to not > cache. > Can anyone give some insight into where the problem might be? It's in Internet Explo

Re: Random Image and Cache problem

2007-09-03 Thread Carl Miller
MAIL PROTECTED]> wrote: > On 09/02/2007 01:16 PM, Carl Miller wrote: >> I'm trying to setup a simple random image script to allow other websites to >> display random banner ads located on my server. >> >> The other website would call the perl script in an tag, lik

Re: Random Image and Cache problem

2007-09-02 Thread Mumia W.
On 09/02/2007 01:16 PM, Carl Miller wrote: I'm trying to setup a simple random image script to allow other websites to display random banner ads located on my server. The other website would call the perl script in an tag, like so: http://www.my_site.com/cgi-bin/random_banner.cgi&qu

Re: Random Image and Cache problem

2007-09-02 Thread Gunnar Hjalmarsson
Carl Miller wrote: I'm trying to setup a simple random image script to allow other websites to display random banner ads located on my server. The other website would call the perl script in an tag, like so: http://www.my_site.com/cgi-bin/random_banner.cgi"; width="468"

Random Image and Cache problem

2007-09-02 Thread Carl Miller
I'm trying to setup a simple random image script to allow other websites to display random banner ads located on my server. The other website would call the perl script in an tag, like so: http://www.my_site.com/cgi-bin/random_banner.cgi"; width="468" height="60&q

library (random numbers)

2007-08-07 Thread Amichai Teumim
Does this make any sense? Here is the script again: #!/usr/bin/perl use strict; use warnings; require 'obj13-lib.pl'; my @userArray = ; my $sum = sumIt(@userArray); print $sum; And here is the library: sub sumIt{ my $total; $total += $_ for @_; warn "@_ was empty, total undefined!\n" i

Re: library (random numbers)

2007-08-07 Thread Amichai Teumim
Yeah I think it was a comment. I removed it now. Thanks ;) Jeff Pang wrote: > -Original Message- > >> From: Amichai Teumim <[EMAIL PROTECTED]> >> Sent: Aug 6, 2007 10:34 AM >> To: "Mr. Shawn H. Corey" <[EMAIL PROTECTED]> >> Cc: beginn

Re: library (random numbers)

2007-08-07 Thread Martin Barth
On Tue, 07 Aug 2007 11:23:05 +0300 Amichai Teumim <[EMAIL PROTECTED]> wrote: > > Line 11 n obj13-lib.pl is: > > (last index). Double check > > I don't know what could be wrong with this syntax, as I have never used > these commands before. I thought it migh need a curly, but I get the > same er

Re: library (random numbers)

2007-08-07 Thread Jeff Pang
-Original Message- >From: Amichai Teumim <[EMAIL PROTECTED]> >Sent: Aug 6, 2007 10:34 AM >To: "Mr. Shawn H. Corey" <[EMAIL PROTECTED]> >Cc: beginners@perl.org >Subject: Re: library (random numbers) > >I just renamed it to obj13-1.pl from script

library (random numbers)

2007-08-07 Thread Amichai Teumim
Line 11 n obj13-lib.pl is: (last index). Double check I don't know what could be wrong with this syntax, as I have never used these commands before. I thought it migh need a curly, but I get the same error. Mr. Shawn H. Corey wrote: > Amichai Teumim wrote: >> I get: >> >> Not enough argument

Re: library (random numbers)

2007-08-07 Thread Amichai Teumim
So that makes sense. (last index). Double check shouldn't even be there. I must have incompletely removed the comment. So I should just delete it or comment it out? Chas Owens wrote: > On 8/6/07, Amichai Teumim <[EMAIL PROTECTED]> wrote: > snip > >> sub sumIt{ >> my $total; >> $total += $

Re: library (random numbers)

2007-08-07 Thread A. Teumim - Netgear Support
So this is what I have now in my library: sub sumIt{ my $total; $total += $_ for @_; warn "@_ was empty, total undefined!\n" if !defined $total; } sub avg(@) { my @arr = @_; my $arrSize = scalar(@arr); #(last index). Double check; return sumIt(@arr) / @arr; } 1; Why is return sumIt(@arr

Re: library (random numbers)

2007-08-06 Thread Mr. Shawn H. Corey
Amichai Teumim wrote: I get: Not enough arguments for index at obj13-lib.pl line 11, near "index)" Compilation failed in require at obj13-1.pl line 6. What is this index error? Go to line 11 in obj13-lib.pl and check its syntax. -- Just my 0.0002 million dollars worth, Shawn "For the

Re: library (random numbers)

2007-08-06 Thread Chas Owens
On 8/6/07, Amichai Teumim <[EMAIL PROTECTED]> wrote: snip > sub sumIt{ > my $total; > $total += $_ for @_; > warn "@_ was empty, total undefined!\n" if !defined $total; > } snip This will return nothing useful. You need a return statement after the warn. > sub avg(@) > { > my @arr = @_; > m

Re: library (random numbers)

2007-08-06 Thread Amichai Teumim
I just renamed it to obj13-1.pl from script.pl So it looks now like this: #!/usr/bin/perl use strict; use warnings; require 'obj13-lib.pl'; my @userArray = ; my $sum = sumIt(@userArray); print $sum; and the library I renamed to: obj13-lib.pl and now looks like this: sub sumIt{ my $total;

Re: library (random numbers)

2007-08-06 Thread Amichai Teumim
No it was commented out. Now it's changed. I still don't know how to use it. What would a good way to test it be? echo 1234 | ./script.pl obviously won't do much. I wad told ./obj13-1.pl < Paul Lalli wrote: >> Yes, it would have, if that's what you had. But you didn't. You had >> the line: >> #

Re: library (random numbers)

2007-08-06 Thread Paul Lalli
On Aug 6, 9:03 am, [EMAIL PROTECTED] (Mr. Shawn H. Corey) wrote: > Paul Lalli wrote: > > Yes, it would have, if that's what you had. But you didn't. You had > > the line: > > #require 'lib.pl' > > > That is, you had the line commented out. A commented out line does > > nothing at all. > > > Paul

Re: library (random numbers)

2007-08-06 Thread Paul Lalli
On Aug 6, 9:03 am, [EMAIL PROTECTED] (Mr. Shawn H. Corey) wrote: > Paul Lalli wrote: > > Yes, it would have, if that's what you had. But you didn't. You had > > the line: > > #require 'lib.pl' > > > That is, you had the line commented out. A commented out line does > > nothing at all. > > > Paul

Re: library (random numbers)

2007-08-06 Thread Mr. Shawn H. Corey
Amichai Teumim wrote: No it was commented out. Now it's changed. I still don't know how to use it. What would a good way to test it be? echo 1234 | ./script.pl obviously won't do much. I wad told ./obj13-1.pl < What the heck is obj13-1.pl? To test your script you need a list of numbers one

Re: library (random numbers)

2007-08-06 Thread Amichai Teumim
When I do this, I get : ./script.pl < line 3. #!/usr/bin/perl #require 'script.pl'; @userArray = ; $sum = sumIt(@userArray); print $sum; Mr. Shawn H. Corey wrote: > Amichai Teumim wrote: >> ./script.pl | echo 1234 >> >> Or is this nonsensical? Very very new to Perl. > > This is actually sh

Re: library (random numbers)

2007-08-06 Thread Mr. Shawn H. Corey
Paul Lalli wrote: Yes, it would have, if that's what you had. But you didn't. You had the line: #require 'lib.pl' That is, you had the line commented out. A commented out line does nothing at all. Paul Lalli Actually, in the post I replied to it was: #require 'script.pl'; The OP seems t

Re: library (random numbers)

2007-08-06 Thread Paul Lalli
On Aug 6, 7:56 am, [EMAIL PROTECTED] (Amichai Teumim) wrote: > Mr. Shawn H. Corey wrote: > > Amichai Teumim wrote: > >> #!/usr/bin/perl > >> #require 'lib.pl'; > > require 'lib.pl'; > >> @userArray = ; > >> $sum = sumIt(@userArray); > >> print $sum; > > > If the sub sumIt() is in the file lib.pl,

Re: library (random numbers)

2007-08-06 Thread Paul Lalli
On Aug 6, 6:52 am, [EMAIL PROTECTED] (Amichai Teumim) wrote: > This is pure educational. I want to understand how this all works. > > So after follow your comments my script.pl looks like this: > > !/usr/bin/perl This shebang is incorrect. Specifically, you're missing the "sh" part of "shebang":

Re: library (random numbers)

2007-08-06 Thread Amichai Teumim
I thought that require 'lib.pl'; was telling Perl where to find it. Mr. Shawn H. Corey wrote: > Amichai Teumim wrote: >> When I do this, I get : >> >> ./script.pl <> 1234 >> 5678 >> 90 >> EOD >> >> Undefined subroutine &main::sumIt called at ./script.pl line 7, >> line 3. >> >> #!/usr/bin/perl

Re: library (random numbers)

2007-08-06 Thread Amichai Teumim
Hi Paul This is pure educational. I want to understand how this all works. So after follow your comments my script.pl looks like this: !/usr/bin/perl use strict; use warnings; require 'lib.pl'; my @userArray = ; my $sum = sumIt(@userArray); print $sum; AND my library like this: sub sumIt(

Re: library (random numbers)

2007-08-06 Thread Mr. Shawn H. Corey
Amichai Teumim wrote: When I do this, I get : ./script.pl < line 3. #!/usr/bin/perl #require 'script.pl'; require 'lib.pl'; @userArray = ; $sum = sumIt(@userArray); print $sum; If the sub sumIt() is in the file lib.pl, you have to tell perl where to find it. -- Just my 0.0002 m

Re: library (random numbers)

2007-08-03 Thread Paul Lalli
On Aug 3, 6:03 am, [EMAIL PROTECTED] (Amichai Teumim) wrote: > After some friendly input from yitzle I might have moved further with > my library. > > This is my script. > > script.pl > > #!/usr/bin/perl Get into the habbit of using use strict; use warnings; in all of your scripts. You will be g

Re: library (random numbers)

2007-08-03 Thread Chas Owens
On 8/3/07, Amichai Teumim <[EMAIL PROTECTED]> wrote: snip > sub sumIt(@) snip > sub avg(@) snip Ack prototypes! They don't do what you think they do. Don't use them until you have read http://library.n0i.net/programming/perl/articles/fm_prototypes and understand it fully. Prototypes are very us

Re: library (random numbers)

2007-08-03 Thread Mr. Shawn H. Corey
Amichai Teumim wrote: ./script.pl | echo 1234 Or is this nonsensical? Very very new to Perl. This is actually shell: echo 1234 | ./script.pl Try: ./script.pl

library (random numbers)

2007-08-03 Thread Amichai Teumim
After some friendly input from yitzle I might have moved further with my library. This is my script. script.pl #!/usr/bin/perl #require 'lib.pl'; @userArray = ; $sum = sumIt(@userArray); print $sum; And this is my library according to yitzle: sub sumIt(@) { my $total = 0; $total += $_

Re: library (random numberS)

2007-07-27 Thread Andy Greenwood
On 7/27/07, yitzle <[EMAIL PROTECTED]> wrote: > I was under the impression that "average" meant mean. correct. Average is the common term for mean. In fact, reading the pages linked above, they do imply (without stating explicitly) that the three terms describe different calculations. I can't thi

Re: library (random numberS)

2007-07-27 Thread yitzle
I was under the impression that "average" meant mean. sub sumIt(@) { my $total = 0; $total += $_ for (@_); return $total; # This line might not be needed... } sub avg(@) { my @arr = @_; my $arrSize = @arr; # scalar(@arr) is the array size - or one less (last index). Double check retur

Re: library (random numberS)

2007-07-27 Thread Chas Owens
On 7/27/07, Amichai Teumim <[EMAIL PROTECTED]> wrote: snip > What do I add here to calculate the average of the numbers? snip Which average do you want (common ones are mean, mode, and median)? Try looking them up on Wikipedia: * http://en.wikipedia.org/wiki/Mean#Arithmetic_mean * http://en.wikip

library (random numberS)

2007-07-27 Thread Amichai Teumim
OK. I think I moved further. So this is my library. ub sumIt(){ @functionArray = @_; foreach $line(@functionArray){ $functionSum += $line; } return $functionSum; } 1; What do I add here to calculate the average of the numbers? thanks Amichai -- To unsubscribe, e-mail: [EMAIL

library (random numbers)

2007-07-27 Thread Amichai Teumim
OK I figured most of this out I think. I want to create a library that contains a function which takes in an array of numbers (random numbers). This function will then calculate the average of these numbers, the total of all these numbers added together, and a new array of numbers which is the

Re: Help creating a random string in Perl

2007-06-12 Thread Randal L. Schwartz
>>>>> "p46921x" == p46921x <[EMAIL PROTECTED]> writes: p46921x> 1. Only characters in the source string are in the random string p46921x> meaning if Z is not in my source string, it will not be in my random p46921x> string. If A and B are in the source s

Re: Help creating a random string in Perl

2007-06-12 Thread Chas Owens
On 6/12/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: snip I can see how to generate a random number between 0 and 6 (meaning I can pick one of the 7 characters in my source string) by using "print int(rand(6))", but I don't know where to being on the second and third

RE: Help creating a random string in Perl

2007-06-12 Thread Brown, Rodrick
Look at crypt(); $ perldoc -f crypt is a good -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Tuesday, June 12, 2007 3:39 PM To: beginners@perl.org Subject: Help creating a random string in Perl Hello, this is perl.beginners and I am really a beginner

Help creating a random string in Perl

2007-06-12 Thread p46921x
Hello, this is perl.beginners and I am really a beginner. This is also my first Google group post so if I am in the wrong group, I am sorry. I need to create a random combination of n-1 characters in a source string. For example if the string is ABcDeFG (7 characters) * I want to execute my perl

Re: Generating random numbers

2007-03-16 Thread Jeff Pang
Another way, my @c = (1,2,3); my @d = (1,2); print join '',$c[int rand @c],$d[int rand @d]; This could generate arbitrary random string other than the numbers of "1 2 3" or "1 2". ie,the original contents could be: my @c = qw(a,b,c); my @d = qw(4,5,6); &g

Re: Generating random numbers

2007-03-16 Thread Chas Owens
On 3/16/07, John W. Krahn <[EMAIL PROTECTED]> wrote: snip > my $num = int rand 3 + 1; That will return either 0, 1, 2 or 3. The addition has higher precedence. snip Yeah, I saw that after I posted. That is what I get for posting untested code. -- To unsubscribe, e-mail: [EMAIL PROTECTED] Fo

Re: Generating random numbers

2007-03-16 Thread Chas Owens
On 3/16/07, Chas Owens <[EMAIL PROTECTED]> wrote: snip If you need a better pseudo-random number than rand can provide and you are using Linux (or possibly other unix like operating systems) you can read from /dev/urandom snip I should have hit CPAN first. The Crypt::Random* module prov

Re: Generating random numbers

2007-03-16 Thread John W. Krahn
Chas Owens wrote: > On 3/16/07, Grant <[EMAIL PROTECTED]> wrote: >> Hello, I need to generate two random numbers. One should be a 1, 2, >> or 3, and the other should be a 1 or 2. How can I do that? > > That depends on your needs. The rand function creates decent qual

Re: Generating random numbers

2007-03-16 Thread Chas Owens
On 3/16/07, Chas Owens <[EMAIL PROTECTED]> wrote: snip my $num = int rand 3 + 1; snip oops, that should be my $num = int rand(3) + 1; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: Generating random numbers

2007-03-16 Thread Chas Owens
On 3/16/07, Grant <[EMAIL PROTECTED]> wrote: Hello, I need to generate two random numbers. One should be a 1, 2, or 3, and the other should be a 1 or 2. How can I do that? - Grant That depends on your needs. The rand function creates decent quality pseudo-random numbers (it calls

Re: Generating random numbers

2007-03-16 Thread John W. Krahn
Grant wrote: > Hello, Hello, > I need to generate two random numbers. One should be a 1, 2, > or 3, int( rand 3 ) + 1 > and the other should be a 1 or 2. int( rand 2 ) + 1 perldoc -f int perldoc -f rand John -- Perl isn't a toolbox, but a small machine shop where you

Generating random numbers

2007-03-16 Thread Grant
Hello, I need to generate two random numbers. One should be a 1, 2, or 3, and the other should be a 1 or 2. How can I do that? - Grant -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

RE: 1, random; 2, unicode

2006-12-27 Thread zhao_bingfeng
> -Original Message- > From: Adriano Allora [mailto:[EMAIL PROTECTED] > Sent: Thursday, December 28, 2006 3:24 AM > To: beginners@perl.org > Subject: 1, random; 2, unicode > > hi to all, > > two questions: > > 1) I need to extract a random item from an h

1, random; 2, unicode

2006-12-27 Thread Adriano Allora
hi to all, two questions: 1) I need to extract a random item from an hash, does exist a function to do it? A module? An implementable and not-too-much-slow flowchart? 2) How to use unicode with perl? If I write "cos'è" in a string and then I print in the stdout that sring, I

Re: Generate random list

2006-05-27 Thread Mike Blezien
Hello, - Original Message - From: "Dr.Ruud" <[EMAIL PROTECTED]> To: Sent: Saturday, May 27, 2006 9:39 AM Subject: Re: Generate random list "Mike Blezien" schreef: sometimes it lists the same image twice within the random array list created. perldoc

Re: Generate random list

2006-05-27 Thread Dr.Ruud
"Mike Blezien" schreef: > sometimes it lists the same image twice within > the random array list created. perldoc -q random (the text about shuffle) -- Affijn, Ruud "Gewoon is een tijger." -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands

Generate random list

2006-05-27 Thread Mike Blezien
Hello, I have simple script that generates a random list of 5 images from a specific folder, but sometimes it lists the same image twice within the random array list created. Is there a better way to generate a list so it will not display the same element twice within the array?? Below is

Re: random #

2005-10-09 Thread Jeff 'japhy' Pinyan
On Oct 9, ZHAO, BING said: is there a single random number generator function in perl? Or do you have any idea/algorithm on how to shuffle the elements in an array? The random number generator is rand(); its documentation is here: perldoc -f rand To shuffle an array, read: perldoc -q

random #

2005-10-09 Thread ZHAO, BING
Hi, is there a single random number generator function in perl? Or do you have any idea/algorithm on how to shuffle the elements in an array? Thank you all. best, -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <h

Trouble installing modules (Net::SSH::Perl, Math::Pari, Crypt::Random)

2004-07-22 Thread Price, Jason (TLR Corp)
for Net::SSH::Perl installed. The install starts bombing out at Crypt::Random (and continues through several other Crypt modules) - it kicks out a number of errors similar to this: t/generator..ok 3/18PARI: *** forbidden division t_REAL % t_INT. at /usr/lib/perl5/site_perl/5.6.1/i386

Random Image script has a problem

2004-04-20 Thread David Gilden
Greetings, In the following script (see below) it should be pulling images from the directory: rand_fp_imgs The debug info looks good, but when I run the script from the URL below it pulls images that I have sitting at the root level. Does anyone have any idea why this might be? Thanks, Dave (k

Re: How Random is Random?

2004-04-02 Thread John W. Krahn
Phil Schaechter wrote: > > > You will note that the documentation says "apparently random order." In > > more recent versions of Perl (IIRC starting at 5.8.1) randomness was > > added to hash keys for security reasons. In previous versions the order > > o

  1   2   3   >