X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=samegame.c;h=b9078eb63533cad6aae386e6547cd64db038c15b;hb=a605a17d05acf4d981219c5e8db3def0b67a5c4a;hp=60e0272fef074adafbcb968120e2f3c0b0499525;hpb=6bce285027a9eacd50b92b5a26e1cd3c5c69a4ca;p=sgt-puzzles.git diff --git a/samegame.c b/samegame.c index 60e0272..b9078eb 100644 --- a/samegame.c +++ b/samegame.c @@ -398,11 +398,6 @@ static void gen_grid(int w, int h, int nc, int *grid, random_state *rs) if (n == 0) break; /* we're done */ - /* - * Shuffle the list. - */ - shuffle(list, n, sizeof(*list), rs); - #ifdef GENERATION_DIAGNOSTICS printf("initial grid:\n"); { @@ -420,13 +415,17 @@ static void gen_grid(int w, int h, int nc, int *grid, random_state *rs) #endif /* - * Now go through the list one element at a time and - * actually attempt to insert something there. + * Now go through the list one element at a time in + * random order, and actually attempt to insert + * something there. */ while (n-- > 0) { int dirs[4], ndirs, dir; - pos = list[n]; + i = random_upto(rs, n+1); + pos = list[i]; + list[i] = list[n]; + x = pos % w; y = pos / w;