self centering random walk within defined range
- From: rob@xxxxxxxxxx
- Date: Sat, 28 Feb 2009 13:29:17 +0100
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";
}
--------------
rob@xxxxxxxxxx
rob.goto10.org
--------------
Attachment:
signature.asc
Description: Digital signature
- Follow-Ups:
- Re: self centering random walk within defined range
- From: Rob Dixon
- Re: self centering random walk within defined range
- Prev by Date: Re: picking largest key by value..
- Next by Date: Re: self centering random walk within defined range
- Previous by thread: Installing Perl DBD, DBI::mysql Modules
- Next by thread: Re: self centering random walk within defined range
- Index(es):
Relevant Pages
|