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 around 0 up and down a bit in each direction
- but it very quickly shoots of into big numbers.
i would like to have a way to contain the output range to between -45 and 45
for example.
anyone have a clue how to do this?
thanks
rob
#!/usr/bin/perl
use strict;
use warnings;
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 $current,"\n";
}
--------------
[email protected]
rob.goto10.org
--------------
signature.asc
Description: Digital signature
