vendredi 31 mars 2017

How to randomly select letters in Java?

I am learning java, and my assignment now is to simulate a chess notation. I have done random int codes, but not sure how to make a random letter code, and the thing is I only need to choose randomly letters from A to H, I have seen random all 26 letter generators, but could not work my way to understand how to generate only A to H. My other concern is will I be able to store char and ints in a matrix [k][8] or do I have to initialise it in a special way? The idea is to create the a class and later try and randomly generate chess notation. At this stage the notations does not have to make sense.

Here is what i used for int random

import java.util.Random;

static Random rnd = new Random();
static int rnd(int A, int B) { 
    return A+rnd.nextInt(B-A+1);

Also how can i make random selection from specified letters that will represent the chess figures?

I don't need exact codes a push to the right direction will be more then enough




Aucun commentaire:

Enregistrer un commentaire