Search This Blog

Yesteryear

Tuesday, February 25, 2014

February 25, 2014


           Today’s blog is not for everyone, but if you ever visit the casino, read on. I can’t tell you how to cheat because I don’t actually know the protocol of gambling, but I have some observations about the programming of the machines. And I can tell you right now, you do not have to know very much about computers to start figuring things out. From that, the next step would be to cheat because once you know, there are just so many ways to do it. The casinos keep things in check by making the systems simple, not complicated.
           Before anybody starts shouting I’m counseling others to break the law, that is not so. Not that it would stop me from doing it anonymously. I hate casinos and gambling. The program I’ve created is very similar to assignments given to most first year computer students in any school around the country. Any one of them is free to interpret the results. While they are focused on making their code work, I am looking at the nature of the outcomes, questioning how the code achieved the results. Thus, my focus is educational and for entertainment only. Any other use is contrary to my intentions.


           [Author's note 2016-02-25: this post originally lacked a photo, so I plugged this one in here later. I call it the Hipstermobile.]

           I’m thinking all this because of success with the die-throwing program. Read about it in today’s addendum. It was chugging along so slowly that I boosted the speed by shutting down all but the non-essentials. Like the screen saver and the completely idiotic Windows programs like Home Group Listener. That last one is one of many memory-wasting applets that network—even on a computer that is not networked. This sped up the die-rolling and the test was completed in eleven hours. The good news is the computer is 99.99999% honest. But don’t trust ‘em. That’s still not 100.00000%.
           While you could run the code below, you cannot easily duplicate the hoops I went through to make the code true. I could now tell you fifty ways to for a computer sneak to add a couple of bytes and most of the world would never know the difference. This subject is so touchy and misunderstood that I’m going to discuss it now. If you gamble, you might want to know this material to at least the depth I cover it. I am a non-gambler so what I consider important may seem no big deal to you. There are reasons why that is.

           First, be aware that a computer does not necessarily have to break any law to cheat you. The house must have a deliberate advantage. My understanding of what casinos call “counters” is people who memorize what has already been played. Every computer-generated game has this capability already built-in and it is used in favor of the house. Is it clear what I’m saying here? Computer gambling, unlike the older mechanical games of chance, is a certain loss. Understand that in theory, a roulette wheel could at least potentially payout twice in a row. This will never happen with a computer unless it malfunctions.
           Why? Because it can’t be allowed even once. If such a pattern ever occurs, it can be observed and reverse-engineered. My program flashed the numbers on the screen to alert the user it was working. It would take just a few minutes to write those numbers into memory and cheat quite legally—if the casino does the cheating, that is. One could base the outcome of the NEXT supposedly random occurrence by examining what had happened in the past. A simple tweak could easily slip past all but the closest inspection of the code. And I happen to know casinos don’t have anyone who does that. They depend on the honesty of companies who construct the games. And, we suppose, the integrity of each company’s disgruntled ex-employees.

           The problem with computers is the random number generator. While the numbers are indeed random—that’s what I was checking—if I ran the program again, the second set of results would be an identical list of random numbers. It is a fact of digital behavior. The only thing stopping you from knowing when to bet is that the number strings are so phenomenally huge. My very next project is to comb through my own results, not looking for a specific number, but my specialty, which means I’m looking for a pattern. If I could isolate a single repetition tied to a single brand of CPU chip, well, I’d be rich by this time next year. Next year? Because I know better than to walk in and make a killing.
           But the casino knows all this, so how do they upset the random number generator? They take pains to make sure the “seed” value to start each series is different. Identical strings are the result of the same “seed” value. The easiest way is to use the computer clock display. Every passing point in time is unique and nobody can predict to the split second when the gambler is going to pull the lever. An algorithm grabs the time value and uses that to trigger a new random series. Another way is to use two generators running at different speeds. There are other ways, I’m sure, but as you see, anything but the simplest approach gets harder to maintain and monitor.

           How would one cheat? It has little to do with gambling. One would seek to trip that random number generator from a fixed time. Did you know the BIOS measures time by the number of seconds since a fixed date in the past? That’s the first thing to exploit. Kick the slot machine plug out of the wall “by accident” and plug it back in. Watch the thing reboot, pretending to cuss in frustration. Read what it says. Even knowing what year the thing was built can tip you off over which date to use. The older the machine, the weaker the CMOS battery. And if the CMOS battery goes dead, guess what date the computer uses?
The actual meaningful digits of my results were:

           33,448 were a number 1
           33,267 were a number 2
           34,291 were a number 3
           32,365 were a number 4
           33,685 were a number 5
           32,945 were a number 6

I am running another trial to see if it comes out the same. I randomized the timer (read the code) so if my next results return the same numbers, or even numbers in the same order, same pattern, same checksum, same average or any same damn pattern I can possibly think of, you can become a gambler. Because you could safely bet your bottom dollar I’ll be all over it like a herd of turtles.
           You see, if it was possible to have made the two billion bets in the twelve hours it took to play the game, I would have been up $958 by sticking on number 3. Even at the phone company, I never made a grand in half a day. And I’m only toying with this gambling thing.

ADDENDUM
           (I’ve been informed MicroSoft changed QBASIC to “Qbasic” and copyrighted the term.)
           Here is the code listing for the die-throwing program. Those who know how can cut and paste this with a text editor and run the application—just remember that MicroSoft will try to change the file extension on you. Head’s up. Also, that dodo from CERN who couldn't type may allow HTML to strip away all the in-line comment blanks, so you'd have to fix that. Genius, my eye. The Swiss are so good, they don't have to use punctuation, but I will say one good thing about them: Their flag is a big plus.
           Allow me to extend the invite to "Patsie the Programmer" to e-mail me if she spots any logic or syntax errors, as we all know she is an expert on these things.
           I have a suggestion. The QBASIC IDE (Integrated Development Environment) is, in my opinion, too difficult to use. The display is chunky and only displays a limited number of lines. My hint is that you use a text editor (such as Notepad) to type out your code, then import it to the IDE for debugging.


' Beginning of Listing
'==========================================================
'PROGRAM NAME: MILDICE.BAS
'LANGUAGE: Qbasic (will not run on QB64)
'TODAY'S DATE: 2014-02-24
'
'DESCRIPTION/HYPOTHESIS: To simulate a large number of die
'throws to test if the results are honest. A tally of each
'result is kept and the totals displayed at the end of the
'test. There is an on-screen graphic display to entertain
'the user. This code is a learning exercise and therefore
'uses only beginner's level commands.

'NOTE: if your copy of this code is cluttered or shows more
'than a 15% ink coverage per page, reopen this file with a
'text editor, such as MicroSoft's Notepad application.

'==========================================================
' Declarations & Variables
'==========================================================
'----------------------------------------------------------
REM This section establishes the variables used to control
REM and accumulate the results of a computer simulation of
REM throwing a single DIE to check for equality of results
'----------------------------------------------------------
REM: set initial value of all variables

vCounter& = 0 'Count the number of throws
vMaxNum& = 0 'Maximum number of throws
vDieValue% = 0 'Record the value of current throw
v1& = 0 'Accumulated tally of "ones"
v2& = 0 ' " " " " " "twos"
v3& = 0 ' " " " " " "threes"
v4& = 0 ' " " " " " "fours"
v5& = 0 ' " " " " " "fives"
v6& = 0 ' " " " " " "sixes"
vUser$ = "" 'User input placeholder

'==========================================================
' Initialize
'==========================================================
'----------------------------------------------------------
REM This section is code executed once each time the program
REM is started. It takes user input for the number of times
REM to roll the dice. Larger numbers can require several
REM days to complete a single program run. The system has
REM been tested to 2,000,000,000 out of theoretical maximum
REM of 2,147,483,647.
'----------------------------------------------------------

RANDOMIZE TIMER 'generate pseudorandom
COLOR 14, 1
CLS
PRINT " Is the computer die honest?"
PRINT " How many times do you want to throw the die?"
PRINT
PRINT " A) 25,000 times"
PRINT " B) 100,000 times"
PRINT " C) 1,000,000 times"
PRINT
INPUT " Choose A, B, or C and press the ENTER key ", vUser$
IF UCASE$(vUser$) = "A" THEN
vMaxNum& = 25000
ELSE
IF UCASE$(vUser$) = "B" THEN
vMaxNum& = 100000
ELSE
IF UCASE$(vUser$) = "C" THEN
vMaxNum& = 1000000
END IF
END IF
END IF
CLS
PRINT
PRINT " You have chosen to roll the die "; vMaxNum&; " times."
PRINT
PRINT " ROLL 'EM!"

VIEW PRINT 6 TO 21 'open small viewport


'==========================================================
' Main Loop
'==========================================================
'----------------------------------------------------------
REM This section simulates a random number between 1 and 6
REM and stores the OCCURENCE of each number in a variable.
REM There are no error codes, in case of an invalid result
REM the program will simply fail or terminate.
'----------------------------------------------------------

FOR vCounter& = 0 TO vMaxNum& STEP 1 'count the throws
vDieValue% = INT(RND * 6) + 1 'read the die

'----------------------------------------------------------

PRINT v1&; v2&; v3&; v4&; v5&; v6&; 'display values
'CLS 'this cmd suspended

'----------------------------------------------------------
REM This section is a series of nested IF-THEN-ELSE commands
REM which duplicate the function of a CASE command. This is
REM intentional, as this code is a learning exercise. Note:
REM C+ programmers - this is code SHOULD look-->PRETTY!
'----------------------------------------------------------

IF vDieValue% = 1 THEN 'examine the die
v1& = v1& + 1 'sort the result
ELSE
IF vDieValue% = 2 THEN
v2& = v2& + 1
ELSE
IF vDieValue% = 3 THEN
v3& = v3& + 1
ELSE
IF vDieValue% = 4 THEN
v4& = v4& + 1
ELSE
IF vDieValue% = 5 THEN
v5& = v5& + 1
ELSE
IF vDieValue% = 6 THEN
v6& = v6& + 1
ELSE
END IF
END IF
END IF
END IF
END IF
END IF

NEXT vCounter& 'do it all again

'==========================================================
' End Main Loop
'==========================================================


'==========================================================
' Results & Analysis
'==========================================================
'----------------------------------------------------------
REM This code executes once per program instance. This
REM is not meant to be the best display of results, but
REM rather representative of statistical analysis.
'----------------------------------------------------------

PRINT
PRINT
PRINT "Here's the results: "
PRINT
PRINT v1&; v2&; v3&; v4&; v5&; v6&
PRINT "==================================================="
PRINT INT((v1& / vCounter&) * 100); "%";
PRINT INT((v2& / vCounter&) * 100); "%";
PRINT INT((v3& / vCounter&) * 100); "%";
PRINT INT((v4& / vCounter&) * 100); "%";
PRINT INT((v5& / vCounter&) * 100); "%";
PRINT INT((v6& / vCounter&) * 100); "%"
PRINT "If percentages are nearly equal, DIE IS HONEST"

END
'==========================================================
' END OF CODE
'==========================================================

'=========================================================='
' Credits Etc.
REM DateStamp 2014-02-24 Hollywood, FL
REM Property of SCCA(1971) and/or DeltaComm
REM All Rights Reserved to legal maximum
REM Based on a discussion of programming code structure
REM by Jag & Mr. A. to emulate rolling a dice an extreme
REM number and use variables to compare the results to
REM what is expected from "Honest" dies, Expectation: each
REM possible result should appear 1/6th of the total.

REM Flowcharting & program design by Broward Robotics
REM Keyboarding and Debugging by Mr. A. Hey, St. Albert,
REM I can't believe you actually read this far!

REM Program Criticisms:
'----------------------------------------------------------
REM 1. The displays are low resolution and should be switched
' to high-res graphics to provide user feedback and indicate
' code is running.

REM 2. The pseudo-random number generator produces a predict-
' able pattern of numbers. This is offset by using the system
' timer as an initial value - but someone (like me) who could
' determine tha tvalue could reset the timer and potentially
' cheat the house.

REM 3. The user input of alphabetic choices A, B, or C
' is not user-friendly for the non-typist. I say so what,
' but then I have no idea if people who can't type represent
' the majority of gamblers.

'=========================================================='
' End of Listing

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Return Home
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++