Re: rand()

2008-07-30 Thread Rob Dixon
Bobby wrote: > > I'm passing @nums values from an html form; so now my @nums = ($list) where > $list = 97000,97005,98000,96100,94003 . The rand funtion now interprets $list > as a string and not integers so the script doesn't works anymore. How do i > convert values wit

Re: rand()

2008-07-30 Thread Chris Charley
From: ""Chris Charley"" From: "Bobby" Newsgroups: perl.beginners Subject: rand() Hi all, How do I use the rand function to print out more than one random number for an array? In the example script below i have an array @nums with a list of numbers; ho

Re: rand()

2008-07-29 Thread Randal L. Schwartz
>>>>> "peng" == peng kyo <[EMAIL PROTECTED]> writes: peng> You may need srand before the rand function. Not in any version of Perl released in the past 8 years or so. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <[EMAIL

Re: rand()

2008-07-28 Thread Mr. Shawn H. Corey
On Mon, 2008-07-28 at 13:17 -0700, Bobby wrote: > How do i convert values with that list from a string to itegers so > that the script will work properly? See `perldoc -f split` -- Just my 0.0002 million dollars worth, Shawn "Where there's duct tape, there's hope." "Perl is the duct tap

Re: rand()

2008-07-28 Thread Bobby
That worked Shawn. Thanks.   I'm passing @nums values from an html form; so now my @nums = ($list) where $list = 97000,97005,98000,96100,94003 . The rand funtion now interprets $list as a string and not integers so the script doesn't works anymore. How do i convert values with that l

Re: rand()

2008-07-28 Thread Chris Charley
- Original Message - From: "Bobby" <[EMAIL PROTECTED]> Newsgroups: perl.beginners To: Sent: Monday, July 28, 2008 10:54 AM Subject: rand() Hi all, How do I use the rand function to print out more than one random number for an array? In the example script below

Re: rand()

2008-07-28 Thread John W. Krahn
Bobby wrote: That helps but how would i just get back an X number of random numbers because @nums could be in the hundreds of unique numbers. For instance, i just want to randomly pickout 4 numbers from a long list of unique numbers in @nums, how would i do that? use List::Util qw' shuffle ';

Re: rand()

2008-07-28 Thread Mr. Shawn H. Corey
ks fine. > > > > use strict; > > use warnings; > > my $max=3; > > my @nums = ("1","10002","10004","10005","10006","14","150"); > > my @randnum = map { $nums[int rand(@nums)] }

Re: rand()

2008-07-28 Thread Aruna Goke
14. How would you use srand to do this? Try the modified code below, it works fine. use strict; use warnings; my $max=3; my @nums = ("1","10002","10004","10005","10006","14","150"); my @randnum = map { $nums[int ra

Re: rand()

2008-07-28 Thread Bobby
rom: [EMAIL PROTECTED] <[EMAIL PROTECTED]> Subject: Re: rand() To: [EMAIL PROTECTED] Cc: beginners@perl.org Date: Monday, July 28, 2008, 9:58 AM On Mon, Jul 28, 2008 at 11:52 PM, Bobby <[EMAIL PROTECTED]> wrote: > Peng, > > > > Could you give me an example code? I want to rando

Re: rand()

2008-07-28 Thread Bobby
make test, has been 20 minutes already;  is that normal? Thanks. --- On Mon, 7/28/08, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: From: [EMAIL PROTECTED] <[EMAIL PROTECTED]> Subject: Re: rand() To: [EMAIL PROTECTED] Cc: beginners@perl.org Date: Monday, July 28, 2008, 9:58 AM On Mon,

Re: rand()

2008-07-28 Thread Bobby
, Aruna Goke <[EMAIL PROTECTED]> wrote: From: Aruna Goke <[EMAIL PROTECTED]> Subject: Re: rand() To: "Perl beginners" Date: Monday, July 28, 2008, 9:54 AM Bobby wrote: > Hi all, > > How do I use the rand function to print out more than one random number for an array

Re: rand()

2008-07-28 Thread peng . kyo
, 14. How would you use srand to do > this? > Try the modified code below, it works fine. use strict; use warnings; my $max=3; my @nums = ("1","10002","10004","10005","10006","14","150"); my @randnum =

Re: rand()

2008-07-28 Thread Aruna Goke
Bobby wrote: Hi all, How do I use the rand function to print out more than one random number for an array? In the example script below i have an array @nums with a list of numbers; how do i print out more than one random numbers from that list (@nums)? Thanks. #!/usr/bin/perl use strict

Re: rand()

2008-07-28 Thread Bobby
to use this function to randomly pick winners for a drawing contest. If so could some one kindly give me some example codes? Thanks.     #!/usr/bin/perl use strict; use warnings; my @nums = ("1","10002","10004","10005","10006","1400

Re: rand()

2008-07-28 Thread peng . kyo
On Mon, Jul 28, 2008 at 10:54 PM, Bobby <[EMAIL PROTECTED]> wrote: > Hi all, > > How do I use the rand function to print out more than one random number for > an array? In the example script below i have an array @nums with a list of > numbers; how do i print out more th

rand()

2008-07-28 Thread Bobby
Hi all,   How do I use the rand function to print out more than one random number for an array? In the example script below i have an array @nums with a list of numbers; how do i print out more than one random numbers from that list (@nums)? Thanks.   #!/usr/bin/perl use strict; use warnings

Re: Max range of rand function?

2008-07-03 Thread matt
On Jul 2, 10:04 pm, [EMAIL PROTECTED] (John W. Krahn) wrote: > howa wrote: > > On 7月2日, 下午11時59分, [EMAIL PROTECTED] (John W. Krahn) wrote: > >> howa wrote: > >>> Hi, > >> Hello, > > >>> I want to have a max range of rand function, so I use &

Re: Max range of rand function?

2008-07-02 Thread John W. Krahn
howa wrote: On 7$B7n(B2$BF|(B, $B2<8a(B11$B;~(B59$BJ,(B, [EMAIL PROTECTED] (John W. Krahn) wrote: howa wrote: Hi, Hello, I want to have a max range of rand function, so I use my $rnd = rand(4294967295) ; However, is it safe to use so, e.g. in 32 bit system? rand() return

Re: Max range of rand function?

2008-07-02 Thread Rob Dixon
John W. Krahn wrote: > howa wrote: >> >> I want to have a max range of rand function, so I use >> >> my $rnd = rand(4294967295) ; >> >> However, is it safe to use so, e.g. in 32 bit system? > > rand() returns a floating point number that is bas

Re: Max range of rand function?

2008-07-02 Thread John W. Krahn
howa wrote: Hi, Hello, I want to have a max range of rand function, so I use my $rnd = rand(4294967295) ; However, is it safe to use so, e.g. in 32 bit system? rand() returns a floating point number that is based on RANDBITS and not the size of the CPU registers, so to see how many bits

Max range of rand function?

2008-07-02 Thread howa
Hi, I want to have a max range of rand function, so I use my $rnd = rand(4294967295) ; However, is it safe to use so, e.g. in 32 bit system? Thanks. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: generating number ranges using rand function

2008-05-05 Thread Rob Dixon
below. >> >> Can someone guide on how to make all come out in 15digits. > > print sprintf( '%.30f', rand ) =~ /\.(\d{15})/; This solution (as well as Gunnar's) relies on the available precision of the rand function, which is determined when Perl is built. The n

Re: generating number ranges using rand function

2008-05-04 Thread Aruna Goke
come out in 15digits. print sprintf( '%.30f', rand ) =~ /\.(\d{15})/; John Thanks nice one. Goksie -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: generating number ranges using rand function

2008-05-04 Thread John W. Krahn
. print sprintf( '%.30f', rand ) =~ /\.(\d{15})/; John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order.-- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For addi

Re: generating number ranges using rand function

2008-05-04 Thread Jenda Krynicky
in_number($$$){ > ($b, $c, $d) = @_; > for($a=0; $a<=10; $a++){ > $ab = int(rand($b)); > $ac = int(rand($c)); > $ad = int(rand($d)); > say $ab, $ac, $ad; 1. Don't say you want them output, printf() them in the requested format printf "%05d%05d%05d\n", $ab, $ac,

Re: generating number ranges using rand function

2008-05-04 Thread Gunnar Hjalmarsson
. Thank you. Goksie #!/usr/bin/perl use warnings; use strict; use Perl6::Say; # make a subrouting to generate random numbers; my ($ab, $ac, $ad, $a, $b, $c, $d); sub pin_number($$$){ ($b, $c, $d) = @_; for($a=0; $a<=10; $a++){ $ab = int(rand($b)); $ac = int(rand($c)); $ad = int(rand($d)); say

generating number ranges using rand function

2008-05-04 Thread Aruna Goke
#!/usr/bin/perl use warnings; use strict; use Perl6::Say; # make a subrouting to generate random numbers; my ($ab, $ac, $ad, $a, $b, $c, $d); sub pin_number($$$){ ($b, $c, $d) = @_; for($a=0; $a<=10; $a++){ $ab = int(rand($b)); $ac = int(rand($c)); $ad = int(rand($d)); say $ab, $ac,

Re: rand problem v2.0

2004-10-28 Thread Gunnar Hjalmarsson
Jeff Borders wrote: Hello, (revised to include entire program, input file, and output) Okay, that's better. :) I've written a simple quiz program and I've run into a problem with rand and the integer it returns. It seems that it will eventually choose either 0 or n+1 (I'm g

rand problem v2.0

2004-10-28 Thread Jeff Borders
Hello, (revised to include entire program, input file, and output) I've written a simple quiz program and I've run into a problem with rand and the integer it returns. It seems that it will eventually choose either 0 or n+1 (I'm guessing) which blows up my array. I want to make

Re: Using rand problem

2004-10-28 Thread Gunnar Hjalmarsson
Jeff Borders wrote: I've written a simple quiz program and I've run into a problem with rand and the integer it returns. It seems that it will eventually choose either 0 or n+1 which blows up my array. I want to make sure it chooses from the entire pool of questions. ie. Don't

Re: Keep track of numbers in a loop with rand

2004-10-28 Thread Steve Bertrand
> Basically, to help me understand the use of HOH's, I'm trying to count > how many times rand() finds each number between 1..100. > > Using Storable, I want to put the result in a file, then retrieve upon > the next run of the script. However, I can not find a suitable &

Using rand problem

2004-10-28 Thread Jeff Borders
Hello, I've written a simple quiz program and I've run into a problem with rand and the integer it returns. It seems that it will eventually choose either 0 or n+1 which blows up my array. I want to make sure it chooses from the entire pool of questions. ie. Don't skip the first

Keep track of numbers in a loop with rand

2004-10-28 Thread Steve Bertrand
Basically, to help me understand the use of HOH's, I'm trying to count how many times rand() finds each number between 1..100. Using Storable, I want to put the result in a file, then retrieve upon the next run of the script. However, I can not find a suitable replacement for the loop

RE: rand < vs rand >

2002-06-20 Thread Jeff 'japhy' Pinyan
On Jun 20, Balint, Jess said: >Are these -l and -n flags specific to perl 5.6? I am using 5.005 and they >don't work as illustrated: The -l and -n flags have been with Perl for quite some time. >% perl -e 'while{print if(.45909592993094279021 < rand);}' db_mlb_un

RE: rand < vs rand >

2002-06-20 Thread Balint, Jess
Are these -l and -n flags specific to perl 5.6? I am using 5.005 and they don't work as illustrated: % perl -e 'while{print if(.45909592993094279021 < rand);}' db_mlb_undup.dat syntax error at -e line 1, near "while{" Execution of -e aborted due to compilation er

Re: rand() function

2002-01-14 Thread Roger C Haslock
> > Another way to determine how randomly the rand() function is working is to plot > it sorted. A bad random function might predominate in a particular area, so > you want to see a straight diagonal line in this case, meaning the results are > spread throughout the range. (This

RE: rand() function

2002-01-14 Thread Gary Hawkins
. D:\PERL\_myStuff\randplot.png File randplot.pl contents... #!perl use Chart::Plot; my $img = Chart::Plot->new(400,400); my @data; for (1..1) { push @data, rand() } $img->setData (\@data, 'black noline points'); open (WR,'>randplot.png') or die (&quo

Re: rand() function

2002-01-13 Thread Roger C Haslock
#x27;" <[EMAIL PROTECTED]>; "Gary Hawkins" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Monday, January 14, 2002 5:19 AM Subject: RE: rand() function > Worked just like stated. I missed that you were pushing on @data and used @dataset when going to the img

RE: rand() function

2002-01-13 Thread Wagner-David
:[EMAIL PROTECTED]] Sent: Saturday, January 12, 2002 08:51 To: Gary Hawkins Cc: [EMAIL PROTECTED] Subject: Re: rand() function You seem to have looked at Chart-Plot. You might try use Chart::Plot; my $img = Chart::Plot->new(400,400); my @data; for (1..1) { push @data, rand() } $

Re: rand() function

2002-01-12 Thread Roger C Haslock
- From: "Wagner-David" <[EMAIL PROTECTED]> To: "'Roger C Haslock'" <[EMAIL PROTECTED]>; "Gary Hawkins" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Thursday, January 10, 2002 8:27 PM Subject: RE: rand() function > What P

Re: rand() function

2002-01-12 Thread Roger C Haslock
You seem to have looked at Chart-Plot. You might try use Chart::Plot; my $img = Chart::Plot->new(400,400); my @data; for (1..1) { push @data, rand() } $img->setData (\@dataset, 'black noline points'); open (WR,'>plot.png') or die ("Failed to write fil

RE: rand() function

2002-01-10 Thread Wagner-David
What Perl module is needed for plot or is this under the browser or Thanks. Wags ;) -Original Message- From: Roger C Haslock [mailto:[EMAIL PROTECTED]] Sent: Thursday, January 10, 2002 11:36 To: Gary Hawkins; [EMAIL PROTECTED] Subject: Re: rand() function My apologies: a typo

Re: rand() function

2002-01-10 Thread Roger C Haslock
My apologies: a typo has crept in For 'plot rand(),read()' Read 'plot rand(),rand()' That is, generate x,y randomly in the interval (0,1). Regards - Roger - - Original Message - From: "Gary Hawkins" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]>

RE: rand() function

2002-01-09 Thread Gary Hawkins
> to take successive pairs, and plot them on a graph. Bad generators would > show distinct lines after a while. > > eg > > for (0..10000) { > plot rand(), read() > } > What would it require to make that do something? >ppm search plot Packages available from htt

Re: rand() function

2002-01-09 Thread Roger C Haslock
A simple test I discovered years ago for pseudo-random number generators was to take successive pairs, and plot them on a graph. Bad generators would show distinct lines after a while. eg for (0..1) { plot rand(), read() } - Roger - - Original Message - From: "Robert H

RE: rand() function

2002-01-07 Thread Gary Hawkins
> > Is there a statistically better solution for generating random numbers than > > Perl's built in rand() function? I noticed a couple modules on CSPAN, but > > are they any better? I haven't done a true test of the spread > regular rand() > > gives, but it

Re: rand() function

2002-01-07 Thread John W. Krahn
Robert Howard wrote: > > Is there a statistically better solution for generating random numbers than > Perl's built in rand() function? I noticed a couple modules on CSPAN, but > are they any better? I haven't done a true test of the spread regular rand() > gives, b

RE: rand() function

2002-01-07 Thread McCollum, Frank
I did a random sampling of 10,000 random numbers in two separate groups : for (0..1) { print rand()."\n" } It seemed to consistently revert towards a mean of 0.50 (i.e. results(1) = 0.503; results(2) = 0.498). I also broke those into groups of 100 and seemed to get the sa

rand() function

2002-01-07 Thread Robert Howard
Is there a statistically better solution for generating random numbers than Perl's built in rand() function? I noticed a couple modules on CSPAN, but are they any better? I haven't done a true test of the spread regular rand() gives, but it seems to me to give numbers closer to the

RE: using rand

2001-10-02 Thread Jeff 'japhy' Pinyan
On Oct 2, Bob Showalter said: >> -Original Message- >> From: eric [mailto:[EMAIL PROTECTED]] >> >> show how to creat a random number inthe following range: >> 5 to 15 >> -10 to 20 >> >> the documentation for rand and srand are not

RE: using rand

2001-10-02 Thread Bob Showalter
> -Original Message- > From: eric [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, October 02, 2001 4:12 AM > To: [EMAIL PROTECTED] > Subject: using rand > > > i'm taking an intro to programming with PERL class. one of > the problems > asks us to do t

using rand

2001-10-02 Thread eric
i'm taking an intro to programming with PERL class. one of the problems asks us to do the following: show how to creat a random number inthe following range: 5 to 15 -10 to 20 the documentation for rand and srand are not too useful. Any help would be great. thanks, eric -- To unsubs