Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 1 of 1

Thread: Help With Generating Random Initial Board For Game Of Life

  1. #1
    Junior Member
    Join Date
    Oct 2014
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help With Generating Random Initial Board For Game Of Life

    So right now, my part is to create the initial generation for Game of Life, randomly. It's hard for me to tell if I am heading in the right direction without writing the rest of the code to see if it works. Can anyone give me some input on what I shouldn't be doing or if it needs to be fixed, thanks.

    private boolean[][] world;
     
     
     
    private static void createRandomWorld {
     
    boolean[][] world = new boolean[10][10];
    		for(int row = 0; row < world.length; row++ ){
    			for(int col = 0; col < world[row].length; col++ ){
    				world[row][col] = (Math.random() < 0.40);
                if (world[row][col] == 0)
                        System.out.print("0");
                    else
                        System.out.print("x");
               }
                 }
                 }
    Last edited by theYe; November 10th, 2017 at 09:07 PM.

Similar Threads

  1. Help generating random permutations from array list
    By mactank13 in forum What's Wrong With My Code?
    Replies: 12
    Last Post: December 2nd, 2012, 09:04 PM
  2. Game of Life 2-D matrix random seed boolean array PLEASE
    By Eriosblood in forum Collections and Generics
    Replies: 20
    Last Post: September 3rd, 2012, 06:10 PM
  3. Generating a Random Coprime Number
    By phleep in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 15th, 2011, 12:12 AM
  4. Generating random numbers
    By abelned in forum Object Oriented Programming
    Replies: 1
    Last Post: September 1st, 2010, 07:24 AM
  5. Generating random letters and numbers together
    By newJava in forum Java Theory & Questions
    Replies: 3
    Last Post: March 19th, 2010, 04:08 AM