Archive for the ‘News’ Category

Shuffling a collection

Thursday, August 9th, 2012

The question

In many games you must add some randomness and that might include shuffling a collection of data.

When playing cards with friends, in real life (whaaa?!) you always hear “shuffle them again, they aren’t well shuffled enough!”, so with a proper Penn & Teller face you keep shuffling the cards, many many times, until enough randomness is introduced.

Translating this in code-land, is enough to do


just one time, or must we do something like:


If so, how many times?

What I asked myself is this: if I shuffle the collection twice, will it be more shuffled or, on the contrary, less shuffled than if I shuffle it only once?

Consider the following collection, unshuffled:

[A, B, C, D, E]

Now we shuffle it and get, for example:

[C, D, B, A, E]

My concern is that if I shuffle it again, the items might pop back in in their original place, hence making the collection less unshuffled. Can this happen? Or will it be just coincidence?

But first, how do we define a distance between collections?

Two ways, that I can think of, are:

1) Positions

Sum the difference of the positions of the elements between them.

With this method we iterate item by item for the first collection and found on which position on the other collection the item is, and calculate the difference between positions. Easier to see with pseudo-code:

int distance(List list1, List list2) {
  int ret = 0;

  for (element : list1) {
    ret += abs(list1.indexOf(element) - list2.indexOf(element));

  return ret;

2) Permutations

Sum how many permutations must be done to the second collection so that it’s on the same order as the first collection. Again, some pseudo-code:

int permutations(List list1, List list2) {
  int ret = 0;

  for (T element : list1) {
    int posList1 = list1.indexOf(element);
    int posList2 = list2.indexOf(element);

    if (posList1 != posList2) {
      temp = list2.get(posList1);

      list2.set(posList1, element);
      list2.set(posList2, temp);


  return ret;

With these two über powerful tools, we are ready to find da answer to the question.

The idea is to try and see the distances between the original collection, and a shuffled collection, and compare the results with 2 shuffles, 3 shuffles, et cetera.


Size 5

Size 5

Size 10

Size 10

Size 25

Size 25

The raw data is uploaded here as a google doc

Hence, it’s straightforward: shuffle them as many times you feel like, they’ll have the same entropy

tl;dr: it doesn’t matter how many times you shuffle a collection, as long as the shuffle function is ok, it’s all the same

Global Game Jam in Argentina

Saturday, December 26th, 2009

The 2010 GGJ will take place January 29-31, 2010 in more than 30 countries around the world including: Argentina, Australia, Belgium, Brazil, Canada, Denmark, UK, Finland, France, Germany, Ireland, Israel, Italy, Japan, Lithuania , Mexico , The Netherlands, New Zealand, Norway, Philippines, Portugal, Qatar, Scotland, South Africa, South Korea, Spain, Sweden, Turkey, USA, Venezuela and Colombia.

Game Jams foster innovation and experimentation. If you have ever wanted to make a game, be a part of a team, or go outside of your usual working method, then a game jam is for you. It’s all about making games and in the GGJ you’re part of a global experiment in creativity. A game jam is not for the faint of heart though. It’s two days of hard work, experimentation, little sleep, collaboration, cramped quarters, new friends, great idea, laughs, technical issues and the time of your life.

In this edition, we are proud to announce that, at least for now, two Argentinian cities are participating in the GGJ: Buenos Aires and Santa Fé.

In both cases there is no entrance fee, but there are limited availability. In order to sign up or for further information, visit the Global Game Jam site or (Buenos Aires, in spanish) or (Santa Fé, in spanish)

Talking @ GDC ‘09

Wednesday, February 25th, 2009

This year I’ll be going to the GDC, and I even get to talk a little about Darkstar on a lecture!

If you would like to meet me there, just send me an e-mail (andres at jengibre), leave a comment or just go to the contact section.

See you there!

Darkstris, grand prize winner

Monday, February 16th, 2009

Darkstris, a cooperative multiplayer tetris game was the grand prize winner in the non-student category of the Project Darkstar Developer Challenge.

Project Darkstar it’s a platform targeted for the development of massive multiplayer games, virtual worlds and social networking applications, created by  Sun Microsystems.

More info on the other participating projects and winners