## Random number generator using modulo

You have probably heard about modulo bias using random number generator. If you read Effective Java by Joshua Bloch this problem is described in Item 47. But did you ever think why there is a problem with simple code like this `Math.abs(rnd.nextInt()) % n`

? Why the distribution of elements is not equal and by how much is it exactly biased? Here is the mathematical explanation:

## What to mock and why not to mock data objects?

Recently when reviewing my code before opening a pull request, I have noticed a few methods that I felt were untested. I have run all tests with coverage and indeed 7 methods in the class were not covered. The class was a data object and all these 7 methods were mostly getters and setters so the following questions arose:

- Should I have a unit test for data object?
- Should I be testing getters and setters?
- Why I never had to do this before?

## TDD learning materials

Recently I have been giving internal presentation in Gamesys about how to do Test Driven Development. A simple exercise is available in my github repository. Extra thanks to Mani Sarkar for his input in preparing this exercise.

## Magic The Gathering

Recently I have enjoyed Christmas sales on Steam and bought a few products really cheap – among others I bought a new decks to Magic The Gathering: Duel of Planewalkers 2012.

After playing a few times against the computer (whose AI is sometimes really dumb) I started thinking about playing against my friends and hence restoring the work on my MTG project.

I wonder if I will be able to go together with my studies, MSci project, work and MTG project…

## MSci Individual Project

This is my fourth and final year at King’s College London, hence I have to do MSci Individual Project.

I have chosen a topic “Flag Co-ordination around a Circle”.

## Software Engineering Group Project

Last year at King’s College London I have been doing a module called Software Engineering Group Project. I did not use git at that time, but as it is the biggest C++ project I have been working on, I decided to show our work now.

Read the rest of this entry

## What’s the next element of the sequence?

Recently I have been applying for the summer internships and one of the recruitment processes has really surprised me. I have submitted an application, I have been asked to take an online aptitude test, finally I have been invited for an interview and a set of tests in company’s office. Everything is fine so far, but things started to change on the day I visited the office – when I was given one of the tests. The whole test was about guessing what is the next element in the sequence!

## Sudoku Helper 1.45

## Sudoku Helper 1.3

There are huge changes in the solving algorithm. It now solves 9×9 Sudoku (or finds out that it is unsolvable) in less than 15ms. It also solves 99% of Sudoku 16×16 with 40 random numbers in less than 1 second. The remaining 1% is solved in over 5 minutes, but I have also found such a Sudoku that my algorithm was unable to solve in 30 minutes. If you like challenges and would like to show me that your skills are much better than my programming skills, feel free to solve it – you will find it below. Solving algorithm also now has a 2 second timeout, so the program will no longer freeze, but will display a message “too complex puzzle”. I am going to implement over the weekend a Sudoku generator that generates puzzles with one unique solution. But for now, here is a jar file and here is the code.

Read the rest of this entry

## Sudoku solving/generating

Since yesterday I have been working on the Sudoku solving and generating algorithms. Even though there is some progress and I extended my current solving algorithm, it is far from being perfect. I am afraid that I will not run away from making a mathematical description of a problem what does not encourage me to work… So what have I done and found out?

Read the rest of this entry