Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Re: Rolling a biased die

by ferrency (Deacon)
on Apr 12, 2002 at 13:39 UTC ( #158567=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my %bias = (1 => 1, 2 => 1);
    
  2. or download this
    $rand = $k if rand($sum += $v) <= $v; 
    # This simplifies to: 
    # $rand = 1 if rand(1) <= 1
    # this is always true.  That's wrong.
    
  3. or download this
    my $sum = 0;
    $sum += $_ foreach (values %bias);
    ...
            last;
        }
    }
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://158567]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2019-01-21 05:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    After Perl5, I'm mostly interested in:
































    Results (352 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!