• 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

To respond to the card question (and coin flipping for that matter), it appears random. It is not, really. A simple thought experiment:

You have two cards, one red and one black. You take note of which is which before they are inverted and slowly "shuffled". You are able to track which is which, and "guess" correctly which will be drawn.

The same principle applies to a full deck of cards. If you know enough about the physics of each, you can determine not only the 50/50 odds, but exactly what card it will be.


And if we know enough about the physics of Pixie Dust we can locate the Pixie Fairies and join Peter Pan on a wild adventure.

Or maybe if we knew enough about the physics of a pot of gold under a rainbow we would be richer.

Wild fantasies about the omniscience required to calculate whatnot and figure out whatchamacallit... and all stems from lack of understanding of PHYSICAL REALITY.


However, we don't practically know enough, so we call it random, even though it was entirely deterministic, at least in theory.


Yup... you are right... "we" do not know practically nor theoretically so who does? The Borg Queen or Q?

"entirely deterministic at least in theory"... so is the dragon in my garage too.

But until you make the theory practical facts then all you are doing is bare asserting baseless wishful thinking.
 
Last edited:
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.

For those of you concerned about portability, I would like to report my findings.

I wrote the script in bash, using a version of bash for MacOS provided by the Homebrew Mac package manager.

I copied and pasted the script as-is directly from the Homebrew vim interface into the Chrome for Mac browser text field, using the MacOS functions for copying and pasting.

Today, I visited the forum in Chrome for Windows, and used the Windows copy/paste functions to copy the script as it appeared in the browser, and paste it into an Ubuntu terminal window.

I'm using the Ubuntu distro provided with Windows 11.

From there, I made two changes. First, I changed the shebang to the local environment's bash path. Second, I gave the file execute permissions.

After that I was able to run it just fine, without any carriage return/end of line issues.
 
To respond to the card question (and coin flipping for that matter), it appears random. It is not, really. A simple thought experiment:

You have two cards, one red and one black. You take note of which is which before they are inverted and slowly "shuffled". You are able to track which is which, and "guess" correctly which will be drawn.

The same principle applies to a full deck of cards. If you know enough about the physics of each, you can determine not only the 50/50 odds, but exactly what card it will be.

However, we don't practically know enough, so we call it random, even though it was entirely deterministic, at least in theory.

Indeed, but in this case it's even sillier. As far as my understanding of what Leumas is doing.

Even if you do shuffle the cards so they are randomly distributed you are then looking at the shuffled deck and using a completely deterministic process to decide what card to pick.

So if you copy the same arrangement of cards and provide the same inputs you come out with the same output.


Let's say that one picks the 20th card from the right side of a shuffled and spread out deck of cards every time.

That is not just deterministic... it is not even random
But the deck is shuffled before one picks the 20th card from the right.

Now the deck is not even random numbers... it is the same deck of cards... no?

Do you think anyone can determine whether a red (diamonds/hearts) or black (clubs/spades) card will be drawn??


So
  • We have the same deck of cards... no random numbers or changing at all.
  • We have the same card position picked every single time... not random or not even unknown... fully determined
  • But the cards deck is shuffled before every pick... from the same deck... from the same position

Is the resulting pick (red or black) random?

Is it deterministic? If you say yes... then by whom or what?

The highlighted shows a fundamental misunderstanding of the nature of randomness. It is more than simply unpredictable - it is actually indeterminate until it has happened.

Good pseudorandom number generators are very difficult to predict but the clue is in the prefix, "pseudo"
 
...
And each time the flip is done a new seed is used so a new sequence is generated from which one result is used for the flip.
...

No. Other than by a wholesale re-initialization of the javascript environment, Math.random() doesn't reseed itself. It just uses its previous value to "seed" the next.

It may be worth noting, too, that the language specification provides no mechanism whatsoever to seed Math.random().
 
Why have you not answered the questions paused below.... is it because they demonstrate how wrong you are about the inherent randomness of the process???

Not at all. I do not see them as relevant to anything I have put forth in this thread. Is there some specific statement of mine that you feel relates to your questions? I'd rather discuss it directly instead of trying to come at via some cryptic aside.
 
So if you copy the same arrangement of cards and provide the same inputs you come out with the same output.


Why would you do that... that is called CHEATING... can you determine the a proper UNFIXED shuffling sequence?

Not you? Then who??

Excellent avoidance of answering the question by adding your own made up FIX.


If you do not FIX the cards... is it random or not?


The highlighted shows a fundamental misunderstanding of the nature of randomness.


By you... yes.... random means indeterministic... if you think otherwise then the lack of understanding is yours not mine.

Cheating and fixing the process does not count.


It is more than simply unpredictable - it is actually indeterminate until it has happened.


Hahaha... yes... until you pick a card it is random... after that you know it.

Well done... you got it... it is random until you draw it you have no idea what it is going to be.... :thumbsup:


Good pseudorandom number generators are very difficult to predict but the clue is in the prefix, "pseudo"


And the above shows fundamental misunderstanding of what PRNGs are.

I already explained for you how a PRNG can be completely unpredictable unless one is OMNISCIENT.

Nor you nor any human or gadget of humanity will ever be OMNISCIENT.

So unless you locate an omniscient sentience to do the determining of the UNFIXED properly shuffled card deck even if you pick the same card position every time, it still will not be deterministic...

Unless you are omniscient... you are not nor any human.

So it is indeterministic.... thanks for admitting it.... QED!!!
 
Last edited:
No. Other than by a wholesale re-initialization of the javascript environment, Math.random() doesn't reseed itself.

Yes it does... you have just said it does...

It just uses its previous value to "seed" the next.


Using a seed to reseed itself is call reseeding itself.

And the fact that the seed is random means the next value is random and the next and the next.

BUT...

You do not know how it does its reseeding... as you said

It may be worth noting, too, that the language specification provides no mechanism whatsoever to seed Math.random().


So you do not know... you are just speculating then... no?

But... even if you are correct.... reseeding itself is reseeding itself... get that?

And when reseeding happens the next sequence is different from the one before and is random.

If the first seed is an instant in time then unless you are OMNIPRESENT and OMNISCIENT you cannot figure out the first seed and thus not any other of the seeds and thus totally random numbers.

And what you said is that you doubt it can generate 109 random numbers.... can you now see that it can???

And why are you still harping on and on about this red herring... I thought you already chucked it back into the ocean????

In all seriousness, I think you are focusing too much on the whole "true" random number generator thing. The pseudorandom number generator provided by the standard Javascript implementations is actually very good. Your attempts to introduce atmospheric noise data is problematic and not likely to produce a clean result. On the other hand, the PRNG function is well behaved and robust.
 
Last edited:
Not at all. I do not see them as relevant to anything I have put forth in this thread. Is there some specific statement of mine that you feel relates to your questions? I'd rather discuss it directly instead of trying to come at via some cryptic aside.


uhuh ... :rolleyes:
 
It will forver oscillate like this although you are correct it is closer to the 50%... BUT NEVER CONVERGES on it.
Repeatedly bare asserting this error of yours will not ever make it converge to any truth.


Not surprisingly, after accusing others of not understanding what convergence is, you demonstrate that it is actually you who doesn't understand. Convergence is a limit concept. If p'n is the proportion of heads in a sample of n coin flips then the limit of p'n as n —> inf. is .5 (assuming the coin is unbiased); that is, p'n converges to .5 as n —> inf. This an example of the Law of Large Numbers. For a Bernoulli random variable (like a coin flip) the law was proved over 300 years ago. That's why I said in my first post that there is nothing new to be learned from your app.
 
For those of you concerned about portability, I would like to report my findings.

I wrote the script in bash, using a version of bash for MacOS provided by the Homebrew Mac package manager.

I copied and pasted the script as-is directly from the Homebrew vim interface into the Chrome for Mac browser text field, using the MacOS functions for copying and pasting.

Today, I visited the forum in Chrome for Windows, and used the Windows copy/paste functions to copy the script as it appeared in the browser, and paste it into an Ubuntu terminal window.

I'm using the Ubuntu distro provided with Windows 11.

From there, I made two changes. First, I changed the shebang to the local environment's bash path. Second, I gave the file execute permissions.

After that I was able to run it just fine, without any carriage return/end of line issues.


Wonderful... :thumbsup:

But still unfortunately lots of massaging and cajoling and copying and pasting and fiddling to make it run... not something just anyone can do with just the touch of a finger to run it on an iPhone 5 or a Fire Tablet or an iPad 6???

[IMGW=100]http://godisadeadbeatdad.com/CoinFlipperImages/iPhone.png[/IMGW]

[IMGW=300]http://godisadeadbeatdad.com/CoinFlipperImages/iPad.png[/IMGW]

[IMGW=300]http://godisadeadbeatdad.com/CoinFlipperImages/Fire.png[/IMGW]​
 
Not surprisingly, after accusing others of not understanding what convergence is, you demonstrate that it is actually you who doesn't understand. Convergence is a limit concept. If p'n is the proportion of heads in a sample of n coin flips then the limit of p'n as n —> inf. is .5 (assuming the coin is unbiased); that is, p'n converges to .5 as n —> inf. This an example of the Law of Large Numbers. For a Bernoulli random variable (like a coin flip) the law was proved over 300 years ago. That's why I said in my first post that there is nothing new to be learned from your app.


:dl:

Thanks... yet again ... for all your incessant and emotional CONCERN.... QED!!!
 
Last edited:
No. Other than by a wholesale re-initialization of the javascript environment, Math.random() doesn't reseed itself.

Yes it does... you have just said it does...

It just uses its previous value to "seed" the next.

This is beyond lunacy.

Leumas, I questioned the appropriateness of pulling a sequence of one billion or so values from Math.random(), and you insisted each call to Math.random() was somehow getting randomized (you even likened it to the RANDOMIZE TIMER idiom in BASIC) and therefore starting a new sequence.

It doesn't do that.

Random number generators have one or more values used as seeds that are manipulated each time the generator is called. From those, the next "random" value is calculated. The manipulated seeds are preserved for the next call to the generator.

My statement that the previous value is used to seed the next is perfectly correct. My other statement was corrected, too: There is no REseeding, that is re-randomizing, the generator.

I think the meaning of what I wrote was perfectly clear. Others are invited to comment it they disagree. As for you, Leumas, you are too quick trying to find fault (which usually isn't there) at the expense of your reading comprehension.
 
Not at all. I do not see them as relevant to anything I have put forth in this thread. Is there some specific statement of mine that you feel relates to your questions? I'd rather discuss it directly instead of trying to come at via some cryptic aside.


uhuh ... :rolleyes:


Ok, then. Great. You cannot identify any relevance to your questions.

We are in agreement.
 
Just for fun I threw the running average output of a 10k trial of my script into a file, imported it to Google sheets, and told Google to insert a chart.

This is what the running average of heads as a percentage of total tosses looks like, over 10,000 tosses.

As you can see, it converges pretty quickly towards 50%, just as predicted.

To facilitate things, I made a modified version of my tosserlad.sh script. Behold the indolence and ignorance that is my approach to scripting!

ringlefinch.sh
Code:
#!/usr/bin/bash

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

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

if [ -z ravg.txt ]
  then
    touch ravg.txt
  else
    rm -f ravg.txt
    touch ravg.txt
fi

for ((i=TOSSES; i>=1; i--)); do
  TOSS=$(echo $RANDOM)
  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 $RAVG >> ravg.txt
  sed -i 's/\%//' ravg.txt
done
 

Attachments

  • chart.png
    chart.png
    7.9 KB · Views: 7
Last edited:
...
As you can see, it converges pretty quickly towards 50%, just as predicted.


Wow... I am so pleased to see how inspired you are by this OP.

Well done!!!:thumbsup::thumbsup:

However... anyone with the slightest bit of discernment can easilly see how the graph in fact proves you arrantly wrong.

All you have to do is zoom in a little on the part you call convergent and you can see the erratic oscillations that clearly never settle down as any definition of convergent means...

I appreciate this admirable effort of yours to prove yourself wrong.... well done... and QED!!!

:th:

Here have a look... this is the entire deceptively appearing flat line...
[IMGW=800]http://godisadeadbeatdad.com/CoinFlipperImages/graph.png[/IMGW]​
 
Last edited:
Wow... I am so pleased to see how inspired you are by this OP.

Well done!!!: thumbsup : : thumbsup :

However... anyone with the slightest bit of discernment can easilly see how the graph in fact proves you arrantly wrong.

All you have to do is zoom in a little on the part you call convergent and you can see the erratic oscillations that clearly never settle down as any definition of convergent means...

I appreciate this admirable effort of yours to prove yourself wrong.... well done... and QED!!!

: th :

Here have a look... this is the entire deceptively appearing flat line...
[IMGW=800]http://godisadeadbeatdad.com/CoinFlipperImages/graph.png[/IMGW]​
Never claimed it was flat. Look at that tight oscillation right at the 50% line though. Exactly as predicted. Q.E.D.
 
Wow... I am so pleased to see how inspired you are by this OP.

Well done!!!:thumbsup::thumbsup:

However... anyone with the slightest bit of discernment can easilly see how the graph in fact proves you arrantly wrong.

All you have to do is zoom in a little on the part you call convergent and you can see the erratic oscillations that clearly never settle down as any definition of convergent means...

I appreciate this admirable effort of yours to prove yourself wrong.... well done... and QED!!!

Here have a look... this is the entire deceptively appearing flat line...


Leumas again illustrates that he does not understand convergence, the Law of Large Numbers of which it is a consequence, or the implications of the standard error of a binomial mean p(1–p)/√n.
 
Last edited:
Not surprisingly, after accusing others of not understanding what convergence is, you demonstrate that it is actually you who doesn't understand. Convergence is a limit concept. If p'n is the proportion of heads in a sample of n coin flips then the limit of p'n as n —> inf. is .5 (assuming the coin is unbiased); that is, p'n converges to .5 as n —> inf. This an example of the Law of Large Numbers. For a Bernoulli random variable (like a coin flip) the law was proved over 300 years ago. That's why I said in my first post that there is nothing new to be learned from your app.
To avoid confusion it might be as well to point out that this convergence is only demonstrated for the relative results. That is, the proportion of results being heads converges to 50% as the number of tosses increases.

However, in terms of absolute numbers, the opposite occurs. The results actually diverge. The more often you toss a coin, the greater the likely difference between the number of heads and half the tosses is going to be.
 
For grins, I ran the following javascript, substantially the same as my QBasic code:
Code:
var count = 900000000;
var heads = 0;
var mark = 1;

for (var ctr = 1; ctr <= count; ctr++) {
    if (Math.random() >= .5) heads++;
    if (ctr >= mark) {
        console.log("Iterations ="+ctr+" and heads="+(100*heads/ctr)+"%");
        mark = mark + mark;
    }
}
console.log("Iterations ="+count+" and heads="+(100*heads/ctr)+"%");

...and got this:

Code:
Iterations =1 and heads=0%
Iterations =2 and heads=50%
Iterations =4 and heads=75%
Iterations =8 and heads=75%
Iterations =16 and heads=62.5%
Iterations =32 and heads=53.125%
Iterations =64 and heads=51.5625%
Iterations =128 and heads=49.21875%
Iterations =256 and heads=43.75%
Iterations =512 and heads=47.65625%
Iterations =1024 and heads=47.75390625%
Iterations =2048 and heads=48.876953125%
Iterations =4096 and heads=49.12109375%
Iterations =8192 and heads=49.21875%
Iterations =16384 and heads=50.531005859375%
Iterations =32768 and heads=50.262451171875%
Iterations =65536 and heads=50.2838134765625%
Iterations =131072 and heads=49.945831298828125%
Iterations =262144 and heads=49.97062683105469%
Iterations =524288 and heads=50.072288513183594%
Iterations =1048576 and heads=50.07286071777344%
Iterations =2097152 and heads=50.00476837158203%
Iterations =4194304 and heads=50.008463859558105%
Iterations =8388608 and heads=50.00487565994263%
Iterations =16777216 and heads=49.99263286590576%
Iterations =33554432 and heads=49.98759627342224%
Iterations =67108864 and heads=49.99752193689346%
Iterations =134217728 and heads=49.99260529875755%
Iterations =268435456 and heads=49.998914077878%
Iterations =536870912 and heads=49.99965447932482%
Iterations =900000000 and heads=49.999864055555705%
 
Not surprisingly, after accusing others of not understanding what convergence is, you demonstrate that it is actually you who doesn't understand. Convergence is a limit concept. If p'n is the proportion of heads in a sample of n coin flips then the limit of p'n as n —> inf. is .5 (assuming the coin is unbiased); that is, p'n converges to .5 as n —> inf. This an example of the Law of Large Numbers. For a Bernoulli random variable (like a coin flip) the law was proved over 300 years ago. That's why I said in my first post that there is nothing new to be learned from your app.

To avoid confusion it might be as well to point out that this convergence is only demonstrated for the relative results. That is, the proportion of results being heads converges to 50% as the number of tosses increases.


It applies to any sample mean, in this case, the mean of a Bernoulli random variable.

However, in terms of absolute numbers, the opposite occurs. The results actually diverge. The more often you toss a coin, the greater the likely difference between the number of heads and half the tosses is going to be.


I predict that that will actually increase confusion, for Leumas anyway.
 
Last edited:

Back
Top Bottom