Building a random bettor

For the next season of Fußball-Bundesliga, we’ll use kicktipp for betting on the results, as we have in the previous seasons. This time, we want to introduce additional dummies, ‘Heimsieg’ (home victory) and ‘Zufall’ (randomness), as yardsticks of predictive performance (i. e., if your bets are worse, you should be ashamed).

Of course, for Heimsieg the question is, what exact result should it use (two suggestions are 1:0 and 2:1)? And how should Zufall produce its values? Enter statistics.

Of course, you could just roll dice, subtract one, and use that for the bets, but some results (e. g., 0:5) are rather unlikely to happen in real life. Therefore, the idea is to construct a random bettor which produces results with the same frequencies as historical results.

So I took the results of the last two seasons (Bundesliga 2006/07 and 2007/08) and counted the results (or rather, let the computer do it). A 1:0 is different from a 0:1, of course. There were a total of 612 matches (2 × 34 × 9). Sorted by frequency: 1:1 occured 71 times (11.6%), 1:0 59 times (9.6%), 2:1 57 times (9.3%), 2:0 47 times (7.7%), 0:0 43 times (7.0%), and 1:2, the first loss for the home team, 41 times (6.7%).

The question whether Heimsieg should bet 1:0 or 2:1 is still a matter of taste, as the difference (59 vs. 57 times) is small. For Zufall, the result statistics offer a spectrum which to use for random bets.

Next step would be to predict the results for the next season of Heimsieg and Zufall by running them against the old seasons (with the rule set from kicktipp).

Some comments on programming (after all, this blog is called irgendwasmitcomputern and thus should have a computer angle, at least sometimes):

For counting the occurrences of results, a simple data structure comes handy, the bag (more pompously called multi-set). Python offers dictionaries, which are nearly all you need for a bag (it is amazing what flexibility dictionaries/hashmaps have to offer; Python, JavaScript, Common Lisp are well equipped with them; I can’t understand why Scheme doesn’t establish them in the core language). So, let’s implement a bag in Python:

def bag_add(b, e):
  if e in b: b[e] += 1
  else:     b[e] = 1

bag = {}            # new empty bag
bag_add(bag, (2,1)) # add 2:1 to bag

That’s about it. You see why I love Python’s dictionaries. You just gather all results in the bag; afterwards you have to choose elements randomly, but according to their relative weight (i. e., frequency). Again, this is rather simple:

def bag_choice(b):
  total = sum(b.values())
  r = random.randint(1, total)
  sofar = 0
  for k, v in b.items():
    if sofar < r <= sofar+v: return k
    sofar += v

By the way, Python uses the Mersenne Twister as a random number generator, which is good enough for all practical purposes (with the exception of cryptography, of course). Original paper: M. Matsumoto and T. Nishimura, "Mersenne Twister: A 623-dimensionally equidistributed uniform pseudorandom number generator", ACM Trans. on Modeling and Computer Simulation Vol. 8, No. 1, January pp. 3-30 (1998); also online at

About Daniel Tiggemann

Software-developer living in Cologne, Germany. Was once a physicist, specialized in computer simulations and parallel programming. Now more into JavaScript, web frontend development, and especially mobile computing.
This entry was posted in Programming, Randomness, Soccer. Bookmark the permalink.

858 Responses to Building a random bettor

  1. Pingback: klonopin

  2. Pingback: viagra online without prescription

  3. Pingback: adipex

  4. Pingback: levitra

  5. Pingback: cheap cialis

  6. Pingback: buy cialis

  7. Pingback: cialis online

  8. Pingback: cialis