Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //generador congruencial mixto variable
- //con la prueba de frecuencia y prueba de coridas
- import java.util.Scanner;
- public class Generador
- {
- public static void main(String[] args)
- {
- int N;
- float M,A,B,D,C,R=0;
- Scanner s = new Scanner(System.in);
- System.out.println("Cantidad de Numeros a Generar:");
- N = s.nextInt();
- System.out.println("Modulo: ");
- M = s.nextInt();
- System.out.println("Semillas A: ");
- A = s.nextInt();
- System.out.println("B: ");
- B = s.nextInt();
- System.out.println("D: ");
- D = s.nextInt();
- float[] RL= new float[N];
- char[] andy= new char[N];
- int [] freq= new int [10];
- for(int i=0;i<10;i++){
- freq[i]=0;
- }
- System.out.println("___________________________________");
- System.out.println("Numeros PseudoAleatorios de 0 a 1:");
- for(int i=0;i<N-1;i++){
- C=A+B*D;
- R=C%M;
- A=B;
- B=D;
- D=R;
- R=R/M;
- RL[i]=R;
- if(R > 0 && R < 0.1){
- freq[0]=freq[0]+1;
- }
- if(R > 0.1 && R < 0.2){
- freq[1]=freq[1]+1;
- }
- if(R > 0.2 && R < 0.3){
- freq[2]=freq[2]+1;
- }
- if(R > 0.3 && R < 0.4){
- freq[3]=freq[3]+1;
- }
- if(R > 0.4 && R < 0.5){
- freq[4]=freq[4]+1;
- }
- if(R > 0.5 && R < 0.6){
- freq[5]=freq[5]+1;
- }
- if(R > 0.6 && R < 0.7){
- freq[6]=freq[6]+1;
- }
- if(R > 0.7 && R < 0.8){
- freq[7]=freq[7]+1;
- }
- if(R > 0.8 && R < 0.9){
- freq[8]=freq[8]+1;
- }
- if(R > 0.9 && R < 1){
- freq[9]=freq[9]+1;
- }
- System.out.println(RL[i]);
- if (i>0){
- if(RL[i]>RL[i-1])
- andy[i-1]='0';
- else
- andy[i-1]='1';
- }
- }
- System.out.println("___________________________________");
- System.out.println("Frecuencia de ");
- for(int i=0;i<10;i++){
- System.out.println("Rango "+i+": "+freq[i]);
- }
- System.out.println("___________________________________");
- System.out.println("lista de 0's y 1's");
- for(int i=0;i<10;i++){
- System.out.println(andy[i]);
- }
- System.out.println("___________________________________");
- System.out.println("Los separa en grupo de Frecuencias");
- int repeat=0;
- int [] Repeat= new int [N];
- char aux;
- for(int i=0;i<N;i++){
- if(i==0)
- aux='0';
- else
- aux=andy[i-1];//se comparara con el siguiente o anterior depende
- if(andy[i]==aux){
- System.out.println(andy[i]);
- repeat++;
- }
- else{
- if(andy[i]=='0'||andy[i]=='1'){
- //Repeat[repeat]=Repeat[repeat]+1;
- repeat=0;
- System.out.println(andy[i]);
- repeat++;}
- }
- System.out.println("\t "+repeat);
- }
- /*
- System.out.println("_________Repeat__________________________");
- for(int i=0;i<10;i++){
- System.out.println(Repeat[i]);
- }
- */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement