Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Is this really random?

by Athanasius (Chancellor)
on Nov 22, 2012 at 04:45 UTC ( #1005055=note: print w/replies, xml ) Need Help??

in reply to Is this really random?

From Pseudorandom:

A pseudorandom process is a process that appears to be random but is not. Pseudorandom sequences typically exhibit statistical randomness while being generated by an entirely deterministic causal process.

So yes, the “statistical randomness” guarantees that there is an equal probability of choosing either value.

I notice that it is very rare for me to get 5 heads and 5 tails.

Well, the probability of getting 5 heads in a row followed by 5 tails in a row is 1/1024. But the probability that 10 rolls will result in 5 heads and 5 tails (in any order) is (10!/5!5!)/1024 = 0.246 or approx. 25%, so this should happen around once in every 4 runs of the simulation.

Is there a better way to do this?

Don’t call a sub using the & prefix:

my $value = &coin_toss;

This syntax is used for overriding prototypes, and should be avoided unless you have a good reason to use it. Prefer:

my $value = coin_toss();

Hope that helps,

Athanasius <°(((><contra mundum

Replies are listed 'Best First'.
Re^2: Is this really random?
by Jenda (Abbot) on Nov 22, 2012 at 15:19 UTC

    Overriding prototypes is not all it does!

    sub foo { print "Called foo(" . join(',', @_) . ")\n"; } sub bar { print "Called bar(" . join(',', @_) . ")\n"; print "foo(); : "; foo(); print "&foo; : "; &foo; } bar(1,2,3);

    Enoch was right!
    Enjoy the last years of Rome.

      Also don't forget &foo() which overrides prototypes without the effect of passing along the caller's @_.

      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1005055]
[Mr. Muskrat]: (considered) Re^3: Please help with Regexp::Common needs to be reparented to Re^2: Please help with Regexp::Common
[Mr. Muskrat]: Is it just me or does that timeout issue seems to be happening more often lately?
[Corion]: Mr. Muskrat: I'm not sure if it really happens more often, but I don't exactly know either
[LanX]: yep
[LanX]: more often for some weeks now
[Corion]: I think I'll have to manually (as god) intervene with that node, as the simple reparenting didn't seem to fix the parent/child relationship of the nodes
[Corion]: I think I have an idea but I'll have to open a ticket with on that - hopefully I get to that on the weekend

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (11)
As of 2017-01-19 16:22 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (170 votes). Check out past polls.