• Quick note - the problem with Youtube videos not embedding on the forum appears to have been fixed, thanks to ZiprHead. If you do still see problems let me know.

Moderated Coin Flipper

Exactly... how many angels can stand on the tip of a sewing needle?
I think that probabilities are less abstract than that.

This is all a well established branch of statistics that is involved with p values and Null Hypothesis testing. I never majored in that branch so my skills are a little rudimentary. However, I can come up with some numbers for you.

Let the Null hypothesis be that the coin simulator is unbiased and the p value be 0.05 (this is when the probability of a particular outcome is less than the p value and thus allows us to reject the null hypothesis.

For 10 tosses, you would have to get 2 heads or less to reject the Null hypothesis.
For 100 tosses, you would have to get less than 42 heads to reject the Null hypothesis.
For 1,000 tosses, you would have to get less than 474 heads to reject the Null hypothesis.
For 10,000 tosses, you would have to get less than 4,918 heads to reject the Null hypothesis.
For 100,000 tosses, you would have to get less than 49,740 heads to reject the Null hypothesis.
For 1,000,000 tosses, you would have to get less than 499,180 heads to reject the Null hypothesis.
 
I think that probabilities are less abstract than that.

This is all a well established branch of statistics that is involved with p values and Null Hypothesis testing. I never majored in that branch so my skills are a little rudimentary. However, I can come up with some numbers for you.

Let the Null hypothesis be that the coin simulator is unbiased and the p value be 0.05 (this is when the probability of a particular outcome is less than the p value and thus allows us to reject the null hypothesis.

For 10 tosses, you would have to get 2 heads or less to reject the Null hypothesis.
For 100 tosses, you would have to get less than 42 heads to reject the Null hypothesis.
For 1,000 tosses, you would have to get less than 474 heads to reject the Null hypothesis.
For 10,000 tosses, you would have to get less than 4,918 heads to reject the Null hypothesis.
For 100,000 tosses, you would have to get less than 49,740 heads to reject the Null hypothesis.
For 1,000,000 tosses, you would have to get less than 499,180 heads to reject the Null hypothesis.


:thumbsup::thumbsup:

Thanks....


Final conclusion is that all this relentless indefatigable concern and interest in Coin Flipper 4 (and V1, V2 & V3) proves that the statements below are egregious slander and proven to be false even by the posters themselves and they will never apologize... not to mention the numerous other occasions of slander and rude epithets from the whole "we".

... The fact is your app is trivial. Not only does it do nothing more than illustrate a statisitical fact that has been well understood for hundreds of years, it merely implements a rudimentary random number function, which in R (the programming language I know best) requires exactly one line of code.

Your app contributes exactly nothing to our knowledge of anything. And everybody here—including you—knows it.

At any rate, I did not libel you. I did accuse you of lying. That was because, contrary to your claim about modeling the "edge case", your code did not model the "edge case" in any way that could be described as legitimately actually modeling the "edge case". Your claim was false, and you would not discuss nor clarify nor amend it, so it was false and deliberate. I.e., a lie.



And here is another proof admitted honestly...

I agree that the business about the edge case is a red herring, and I'm surprised that you've put so much effort into implementing it.
 
Last edited:
Have you ever heard of software testing... it is actually a whole job category.

I am very familiar with software testing. And what you have been suggesting aint it.

Have you tried to run the app even once... of course not... because you do not want to find out that your concerns are baseless.

There you go assuming again...and incorrectly.

Your self-claimed agnosticism of the principles of randomness is the reason you mistakenly think so.

I never made any such claim. Why do you persist in making false statements such as this?

Your concerns are baseless.

No, they are quite well-founded. If they were truly baseless,then you'd have ample room to contradict them via intelligent discussion instead of vacuous denials.

I'm prepared to support my 1-in-4-billion probability estimate; are you willing and able to support your 1-in-10,000 counter claim? Hopefully, something a bit more substantive than the usual "am not"/"are so" rhetoric found in this thread.
 
...
The thing is, none of the above has any relevance as to whether the draws are biased. A sequence with a random starting point drawn from a randomly permuted dataset is still biased if that dataset is biased. Your dataset is biased. Therefore, every random sequence you draw form it is biased.
...

It is very clear there are many things relevant to this thread that Leumas does not understand...at all. The latest addition in this set is the difference between population statistics and sample statistics.

If we assume the source for Leumas' 16K data bytes be a "true random number generator", then, yeah, the 16K bytes are a sample of (true) random data. As merely a sample, though, we'd expect it to have some characteristics slightly different from the underlying full dataset.

I.e., the sample is biased.

Other samples could be biased in different ways, but on average, the sample statistics across many, many samples would converge to the population statistics. However, no amount of fiddling with a single sample is going to wash out all bias while preserving its (true) random nature.
 
After going to bed last night a simple fix for the bias toward tails occurred to me.

Just download more random number sequences from your source site (I think you said you could download a thousand a day without incurring any cost?) until you get one that has 20 more values above 127 than below. Append that sequence to the end of your random array.

Your set of numbers will now be evenly distributed with respect to the only subset that matters, big numbers and little numbers.

As a bonus you could also now allow more than 10,000 tries per run if you wanted.
 
After going to bed last night a simple fix for the bias toward tails occurred to me.

Just download more random number sequences from your source site (I think you said you could download a thousand a day without incurring any cost?) until you get one that has 20 more values above 127 than below. Append that sequence to the end of your random array.

Your set of numbers will now be evenly distributed with respect to the only subset that matters, big numbers and little numbers.

As a bonus you could also now allow more than 10,000 tries per run if you wanted.

The sample you'd end up with would still be biased, just in a different way. Keep in mind the original motivation for this thread and the application, as stated in the opening post, "A single coin toss produces an unpredictable result. But we can predict the approximate results of ten thousand coin tosses. Now, is this random?"

By restricting the characteristics of the random number sequence sample as you suggest, you are biasing how much variation from the mean there would be after repeated trials.

The moral of the story: You cannot make a sample more random by making it less random.
 
Last edited:
Being somewhat bored, and also somewhat interested in this discussion, I bashed together the following bit of doggerel. It purports to calculate a running average of (pseudo)random binary choices.

I am not a skilled programmer. This script has no guardrails and no provisions for portability. The output formatting is rudimentary at best. The user experience is ill-considered. I don't even guarantee that the math is correct; the core logic of the running average is a cargo-cult expression copy-pasta'd directly from Stackoverflow. (Honestly the whole thing is just cargo-cult snippets gathered over the years.)

I do, however, aspire to be a good programmer. So, here for your amusement: my "coin tosser". Feedback is welcome. Bug reports will be entered into a backlog and worked in priority order as determined by the product owner.

Some notes:
  • I'm using whatever RNG comes with the Homebrew version of bash that I happen to have installed.
  • I consider this RNG to be more than adequate for my purposes.
  • I'm not trying to simulate a physical coin, so I don't bother modeling the edge case
  • The script runs ten "tosses" by default, but will accept any arbitrary value as an argument for the number of tosses.
  • Non-integer arguments are disgracefully handled.

tosserlad.sh
Code:
#!/opt/homebrew/bin/bash

if [ -z "$1" ]
  then
    TOSSES=10
  else
    TOSSES=$1
fi

TOSS=0
HEADS=0
TAILS=0
RAVG=0

for ((i=TOSSES; i>=1; i--)); do
  echo -n "Tosses: $i | "
  TOSS=$(echo $RANDOM)
  echo -n "Toss: $TOSS | "
  if [ `expr $TOSS % 2` == 0 ]
    then
      HEADS=$((HEADS+1))
    else
      TAILS=$((TAILS+1))
  fi
  TOTAL=$(($HEADS+$TAILS))
  RAVG=$(printf %.2f%% "$((10**3 * 100 * $HEADS/$TOTAL))e-3")
  echo -n "Heads: $HEADS | "
  echo -n "Tails: $TAILS | "
  echo -n "Running Average (Heads): $RAVG "
  echo ""
done
 
Last edited:
The sample you'd end up with would still be biased, just in a different way. Keep in mind the original motivation for this thread and the application, as stated in the opening post, "A single coin toss produces an unpredictable result. But we can predict the approximate results of ten thousand coin tosses. Now, is this random?"

By restricting the characteristics of the random number sequence sample as you suggest, you are biasing how much variation from the mean there would be after repeated trials.

The moral of the story: You cannot make a sample more random by making it less random.

I meant fixed with respect to the problem of being biased toward heads or tails. I think it would fix that. And I think at that point it's doing what Leumas intended. This change would not have any bearing on the question of how truly random it is.
 
Being somewhat bored, and also somewhat interested in this discussion, I bashed together the following bit of doggerel. It purports to calculate a running average of (pseudo)random binary choices.

I am not a skilled programmer. This script has no guardrails and no provisions for portability. The output formatting is rudimentary at best. The user experience is ill-considered. I don't even guarantee that the math is correct; the core logic of the running average is a cargo-cult expression copy-pasta'd directly from Stackoverflow. (Honestly the whole thing is just cargo-cult snippets gathered over the years.)

I do, however, aspire to be a good programmer. So, here for your amusement: my "coin tosser". Feedback is welcome. Bug reports will be entered into a backlog and worked in priority order as determined by the product owner.

Some notes:
  • I'm using whatever RNG comes with the Homebrew version of bash that I happen to have installed.
  • I consider this RNG to be more than adequate for my purposes.
  • I'm not trying to simulate a physical coin, so I don't bother modeling the edge case
  • The script runs ten "tosses" by default, but will accept any arbitrary value as an argument for the number of tosses.
  • Non-integer arguments are disgracefully handled.

tosserlad.sh
Code:
#!/opt/homebrew/bin/bash

if [ -z "$1" ]
  then
    TOSSES=10
  else
    TOSSES=$1
fi

TOSS=0
HEADS=0
TAILS=0
RAVG=0

for ((i=TOSSES; i>=1; i--)); do
  echo -n "Tosses: $i | "
  TOSS=$(echo $RANDOM)
  echo -n "Toss: $TOSS | "
  if [ `expr $TOSS % 2` == 0 ]
    then
      HEADS=$((HEADS+1))
    else
      TAILS=$((TAILS+1))
  fi
  TOTAL=$(($HEADS+$TAILS))
  RAVG=$(printf %.2f%% "$((10**3 * 100 * $HEADS/$TOTAL))e-3")
  echo -n "Heads: $HEADS | "
  echo -n "Tails: $TAILS | "
  echo -n "Running Average (Heads): $RAVG "
  echo ""
done

I like that it shows the running totals, that's cool and illustrates the convergence well.

If I'm reading this correctly you're checking your random number to see if it's even and if so adds one to the HEADS total, and otherwise adds one to the TAILS total.

I don't have bash loaded on the machine I'm currently on so I can't run it, and I'm not a bash expert by any means. But the code looks clean and readable, which is a big plus, and nothing leaps out looking wrong. I assume the RNG output is going to be pretty evenly distributed with respect to odd and even numbers so you should get good results.

I like it.
 
Hit 50% right on the button :)

Code:
Tosses: 7 | Toss: 25044 | Heads: 4999 | Tails: 4995 | Running Average (Heads): 50.02%
Tosses: 6 | Toss: 25579 | Heads: 4999 | Tails: 4996 | Running Average (Heads): 50.01%
Tosses: 5 | Toss: 30947 | Heads: 4999 | Tails: 4997 | Running Average (Heads): 50.01%
Tosses: 4 | Toss: 7631 | Heads: 4999 | Tails: 4998 | Running Average (Heads): 50.01%
Tosses: 3 | Toss: 9360 | Heads: 5000 | Tails: 4998 | Running Average (Heads): 50.01%
Tosses: 2 | Toss: 18665 | Heads: 5000 | Tails: 4999 | Running Average (Heads): 50.01%
Tosses: 1 | Toss: 20339 | Heads: 5000 | Tails: 5000 | Running Average (Heads): 50.00%
 
Thanks! And yeah, if the RNG isn't evenly distributed between evens and odds, I'm boned.

ETA:

Hit 50% right on the button :)

Code:
Tosses: 7 | Toss: 25044 | Heads: 4999 | Tails: 4995 | Running Average (Heads): 50.02%
Tosses: 6 | Toss: 25579 | Heads: 4999 | Tails: 4996 | Running Average (Heads): 50.01%
Tosses: 5 | Toss: 30947 | Heads: 4999 | Tails: 4997 | Running Average (Heads): 50.01%
Tosses: 4 | Toss: 7631 | Heads: 4999 | Tails: 4998 | Running Average (Heads): 50.01%
Tosses: 3 | Toss: 9360 | Heads: 5000 | Tails: 4998 | Running Average (Heads): 50.01%
Tosses: 2 | Toss: 18665 | Heads: 5000 | Tails: 4999 | Running Average (Heads): 50.01%
Tosses: 1 | Toss: 20339 | Heads: 5000 | Tails: 5000 | Running Average (Heads): 50.00%

Haha nice!
 
Being somewhat bored, and also somewhat interested in this discussion, I bashed together the following bit of doggerel. It purports to calculate a running average of (pseudo)random binary choices.

I am not a skilled programmer. This script has no guardrails and no provisions for portability. The output formatting is rudimentary at best. The user experience is ill-considered. I don't even guarantee that the math is correct; the core logic of the running average is a cargo-cult expression copy-pasta'd directly from Stackoverflow. (Honestly the whole thing is just cargo-cult snippets gathered over the years.)

I do, however, aspire to be a good programmer. So, here for your amusement: my "coin tosser". Feedback is welcome. Bug reports will be entered into a backlog and worked in priority order as determined by the product owner.

Some notes:
  • I'm using whatever RNG comes with the Homebrew version of bash that I happen to have installed.
  • I consider this RNG to be more than adequate for my purposes.
  • I'm not trying to simulate a physical coin, so I don't bother modeling the edge case
  • The script runs ten "tosses" by default, but will accept any arbitrary value as an argument for the number of tosses.
  • Non-integer arguments are disgracefully handled.

tosserlad.sh
Code:
#!/opt/homebrew/bin/bash

if [ -z "$1" ]
  then
    TOSSES=10
  else
    TOSSES=$1
fi

TOSS=0
HEADS=0
TAILS=0
RAVG=0

for ((i=TOSSES; i>=1; i--)); do
  echo -n "Tosses: $i | "
  TOSS=$(echo $RANDOM)
  echo -n "Toss: $TOSS | "
  if [ `expr $TOSS % 2` == 0 ]
    then
      HEADS=$((HEADS+1))
    else
      TAILS=$((TAILS+1))
  fi
  TOTAL=$(($HEADS+$TAILS))
  RAVG=$(printf %.2f%% "$((10**3 * 100 * $HEADS/$TOTAL))e-3")
  echo -n "Heads: $HEADS | "
  echo -n "Tails: $TAILS | "
  echo -n "Running Average (Heads): $RAVG "
  echo ""
done

"tosserlad" was a nice touch.
 
I wanna play, too.

QBasic:
Code:
Input "Number of interations:"; count
heads = 0
mark = 1
For ctr = 1 To count
    If Rnd >= .5 Then
        heads = heads + 1
    End If
    If ctr = mark Then
        Print "Interations ="; ctr; " and heads are at "; 100 * heads / ctr; "%"
        mark = mark + mark
    End If
Next ctr
Print "All done at "; count; " and heads are at "; 100 * heads / count; "%"
 
Being somewhat bored, and also somewhat interested in this discussion, I bashed together the following bit of doggerel. It purports to calculate a running average of (pseudo)random binary choices.

I am not a skilled programmer. This script has no guardrails and no provisions for portability. The output formatting is rudimentary at best. The user experience is ill-considered. I don't even guarantee that the math is correct; the core logic of the running average is a cargo-cult expression copy-pasta'd directly from Stackoverflow. (Honestly the whole thing is just cargo-cult snippets gathered over the years.)

I do, however, aspire to be a good programmer. So, here for your amusement: my "coin tosser". Feedback is welcome. Bug reports will be entered into a backlog and worked in priority order as determined by the product owner.

Some notes:
  • I'm using whatever RNG comes with the Homebrew version of bash that I happen to have installed.
  • I consider this RNG to be more than adequate for my purposes.
  • I'm not trying to simulate a physical coin, so I don't bother modeling the edge case
  • The script runs ten "tosses" by default, but will accept any arbitrary value as an argument for the number of tosses.
  • Non-integer arguments are disgracefully handled.

tosserlad.sh


:bigclap


WOW... I am so glad my app was not so pointless and worthless so as to inspire you to such a good effort.

And in Bash no less.... WELL DONE.

I had to modify it just a tad to make it run on standard Debian-Linux bash...

And just copying and pasting it from your code above did not work because of the damned Windows cr/lf and EOF stuff... I tried to strip all of that but in the end I just typed the code by hand. (see below)

Only one comment.... it is not ONE LINE OF CODE THOUGH... hmmm.... I guess it is bloated Linux dressing then... no??:rolleyes:;)

But seriously :thumbsup::thumbsup:

Ah... another comment.... it is a very standard PSEUDO-RNG and not a real dynamics of a real coin toss... so it has nothing to do with a real world randomness... does it now??;)

... insomuch as it eschews simulating a physical coin entirely.


Here is the Debian-Linux bash version (tosser.sh)

Code:
#! /bin/bash

if [ -z "$1" ]
  then
    tosses=10
  else
    tosses=$1
fi

echo $tosses

flip=0
heads=0
tails=0
ravg=0

for((i=tosses; i>=1; i--));
do
  echo -n "Tosses: $i | "
  flip=$(echo $RANDOM)
  echo -n "Toss: $toss | "
  if [ $(($flip%2)) == 0 ]
      then
    heads=$((heads+1))
      else
    tails=$((tails+1))
  fi
  total=$(($heads+$tails))
  ravg=$(printf %.2f%% "$((10**3 * 100 * $heads/$total))e-3")
  echo -n "Heads: $heads | "
  echo -n "Tails: $tails | "
  echo -n "Running Average (Heads): $ravg "
  echo ""
done


And here is the output from three runs.... notice the second run....

Code:
10
Tosses: 10 | Toss:  | Heads: 1 | Tails: 0 | Running Average (Heads): 100.00%
Tosses: 9 | Toss:  | Heads: 1 | Tails: 1 | Running Average (Heads): 50.00%
Tosses: 8 | Toss:  | Heads: 1 | Tails: 2 | Running Average (Heads): 33.33%
Tosses: 7 | Toss:  | Heads: 2 | Tails: 2 | Running Average (Heads): 50.00%
Tosses: 6 | Toss:  | Heads: 3 | Tails: 2 | Running Average (Heads): 60.00%
Tosses: 5 | Toss:  | Heads: 4 | Tails: 2 | Running Average (Heads): 66.67%
Tosses: 4 | Toss:  | Heads: 4 | Tails: 3 | Running Average (Heads): 57.14%
Tosses: 3 | Toss:  | Heads: 5 | Tails: 3 | Running Average (Heads): 62.50%
Tosses: 2 | Toss:  | Heads: 6 | Tails: 3 | Running Average (Heads): 66.67%
Tosses: 1 | Toss:  | Heads: 6 | Tails: 4 | Running Average (Heads): 60.00%
===========

10
Tosses: 10 | Toss:  | Heads: 1 | Tails: 0 | Running Average (Heads): 100.00%
Tosses: 9 | Toss:  | Heads: 1 | Tails: 1 | Running Average (Heads): 50.00%
Tosses: 8 | Toss:  | Heads: 1 | Tails: 2 | Running Average (Heads): 33.33%
Tosses: 7 | Toss:  | Heads: 1 | Tails: 3 | Running Average (Heads): 25.00%
Tosses: 6 | Toss:  | Heads: 1 | Tails: 4 | Running Average (Heads): 20.00%
Tosses: 5 | Toss:  | Heads: 1 | Tails: 5 | Running Average (Heads): 16.67%
Tosses: 4 | Toss:  | Heads: 1 | Tails: 6 | Running Average (Heads): 14.29%
Tosses: 3 | Toss:  | Heads: 1 | Tails: 7 | Running Average (Heads): 12.50%
Tosses: 2 | Toss:  | Heads: 1 | Tails: 8 | Running Average (Heads): 11.11%
Tosses: 1 | Toss:  | Heads: 1 | Tails: 9 | Running Average (Heads): 10.00%
===========

10
Tosses: 10 | Toss:  | Heads: 0 | Tails: 1 | Running Average (Heads): 0.00%
Tosses: 9 | Toss:  | Heads: 0 | Tails: 2 | Running Average (Heads): 0.00%
Tosses: 8 | Toss:  | Heads: 0 | Tails: 3 | Running Average (Heads): 0.00%
Tosses: 7 | Toss:  | Heads: 0 | Tails: 4 | Running Average (Heads): 0.00%
Tosses: 6 | Toss:  | Heads: 1 | Tails: 4 | Running Average (Heads): 20.00%
Tosses: 5 | Toss:  | Heads: 2 | Tails: 4 | Running Average (Heads): 33.33%
Tosses: 4 | Toss:  | Heads: 3 | Tails: 4 | Running Average (Heads): 42.86%
Tosses: 3 | Toss:  | Heads: 4 | Tails: 4 | Running Average (Heads): 50.00%
Tosses: 2 | Toss:  | Heads: 5 | Tails: 4 | Running Average (Heads): 55.55%
Tosses: 1 | Toss:  | Heads: 5 | Tails: 5 | Running Average (Heads): 50.00%
 
Last edited:
Ah... another comment.... it is a very standard PSEUDO-RNG and not a real dynamics of a real coin toss... so it has nothing to do with a real world randomness... does it now??;)

On the other hand, it doesn't naively use a biased hard-coded sample, so it accurately models the outcomes of an unbiased coin.
 
I wanna play, too...


Why? I thought

...trials speak to the quality of the generator he is using and nothing at all to how coins behave.


And all you are doing is using the ages old PSEUDO-RNG of the ages old QBasic?

And where is the accounting for Edge cases??? Or do you command perfection only from others but not yourself???

And I noticed it is not 1 line of code.... I guesss...

Here's my "app," "Coin Flipper R," ver. 0.... On the other hand, it is exactly one line of code....

Sorry, Leumas, jsfisher but all you've done is write 199 13 lines of literal window DOS dressing to implement a one-line program that does nothing more than illustrate the consequences of an elementary probability theorem that was proved over 300 years ago.
... it eschews simulating a physical coin entirely.
 

Back
Top Bottom