[Tfug] random squares

Andrew Ayre andy at britishideas.com
Sun Oct 21 12:59:11 MST 2007


I would:

Seed the random number generator
Create a 2D array, all zeros
Loop n times
  Get random x,y
  Check array[x,y] is 0 -> add mine and set array[x,y] to 1

Andy

christopher floess wrote:
> Hi, everyone. I have to write a program in java that
> involves a 2d array as a game board. Given a number
> in the constructor, I have to assign that many squares
> to be 'mines'. I know I could use math.random(), but
> would anyone recommend a better way to do this?
> 
> ~ Chris
> 
> 

-- 
Andy
PGP Key ID: 0x67090A54




More information about the tfug mailing list