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
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
>>>>> "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
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
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
- 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
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 ';
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)] }
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
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
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,
, 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
, 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 =
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
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
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
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
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
&
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
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
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
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/
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
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/
.
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
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,
.
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
#!/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,
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
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
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
> 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
&
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
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
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
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
>
> 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
. 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
#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
:[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() }
$
-
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
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
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
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]>
> 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
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
> > 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
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
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
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
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
> -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
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
53 matches
Mail list logo