samedi 14 mars 2020

How do I generate (x,y) coordinates with this multiplicative LCG?

I developed the following code in Java:

/**
 * Método que sirve como generador lineal con unos parámetros dados.
 * @param multiplier    multiplicador de la seed dada.
 * @param seed  semilla inicial del programa; indicará en que punto del periodo comienza el generador.
 * @param addition  adición adicional a la semilla.
 * @param modulus   módulo usado.
 * @param num   cantidad de numeros a generar.
 * @return un vector con los valores generados.
 */

public static BigDecimal[] generadorLineal(BigDecimal multiplier, BigDecimal seed, BigDecimal addition, BigDecimal modulus, int num)
{
    BigDecimal numeros[] = new BigDecimal[num];
    numeros[0] = multiplier.multiply(seed);
    numeros[0] = numeros[0].add(addition);
    numeros[0] = numeros[0].remainder(modulus);

    for(int i = 1; i < num; i++){
        numeros[i] = multiplier.multiply(numeros[i-1]);
        numeros[i] = numeros[i].add(addition);
        numeros[i] = numeros[i].remainder(modulus);
    }

    /*for(int i = 0; i < num; i++){ //normalization (0,1)
        numeros[i] = numeros[i].divide(modulus.subtract(BigDecimal.valueOf(1)), 2, RoundingMode.HALF_UP);
    }*/

    return numeros;
}

And having the next example:

LCG Example

I generate 50 randomly points; being actually eight:

  • p1(x1,y1) = (5,5)
  • p2(x2,y2) = (25,25)
  • p3(x3,y3) = (29,29)
  • p4(x4,y4) = (17,17)
  • p5(x5,y5) = (21,21)
  • p6(x6,y6) = (9,9)
  • p7(x7,y7) = (13,13)
  • p8(x8,y8) = (1,1)

The next 42 points are the same period. This is the output that I get:

Output

But, my teacher is telling me that the result is wrong; because it should only be five points and more distributed in the coordinates x,y of my canvas; or put it in another way, my number of points is wrong and my coordinate 'y' is not right. I certainly don't understand why it should be only five different points or how should I generate my 'y' coordinate.

If the period generated by that LCG is eight, doesn't it mean that the program is generating eight different 'x' coordinates for my canvas? I'm really confused and I'm not asking for code; but for some explanation of why my output isn't right.




Aucun commentaire:

Enregistrer un commentaire