1

Sorry if this question is really basic but I'm very new to Java. This is some code that is outside all methods and in a class called "Triangle". These are used by multiple methods in the class:

 static final int COORDS_PER_VERTEX = 3;
 static float triangleCoords[] = {   
        0.0f,  0.622008459f, 0.0f, 
        -0.25f, -0.311004243f, 0.0f, 
        0.25f, -0.311004243f, 0.0f  
};

I would like to be able to change the position of the triangle to a random location every time but I can't make the random number outside a method so how do I make a random number and put it into the matrix? I've tried this but it won't work:

public float settingRandom() {
    Random random = new Random();
    int number = random.nextInt(1000);
    float xPoint = (number/1000);
    return xPoint;
}


static final int COORDS_PER_VERTEX = 3;
static float triangleCoords[] = {   
        xPoint,  0.622008459f, 0.0f, 
        -0.25f, -0.311004243f, 0.0f, 
        0.25f, -0.311004243f, 0.0f 
};

Thanks.

Aswin Abraham
  • 139
  • 1
  • 7

1 Answers1

0

I don't really see the issue, perhaps I am misunderstanding.

However, if your triangleCoords matrix is in a class variable, couldn't you simply write a class method such as the following?

public void changeTriangle(float random) {
    self.triangleCoords[1] = random; //Or whatever you want
}