Hello there. It's me again.

I think I got most of the Pseudorandom code fixed but there's a problem.

// Name: Wesley Montgomery
// Assignment 1 (Pseudorandom Class)
// CS 211 (5:30 PM-7:40 PM)
// Craig Niiyama
// This class creates a Pseudorandom Number as well as returns the number divided by the
// Modulus and creates a list displaying the Number of occurrences between 0.0 to 1.0


public class pseudorandom {
	    private int multi; //The Multiplier
	    private int seed;  //The Seed
	    private int incr;  //The Increment
	    private int modu;  //The Modulus
	    private int answer; //The Answer
	    private double divmod; // The Number gotten by dividing the answer with the Modulus.
	    


	   
	   
	    public pseudorandom (int m, int s, int i, int mod){
	    multi = m;
	    seed = s;
	    incr = i;
	    modu = mod;
	    
	    }	
	    
	    public int GenerateNext() //generates the next Seed
	    {
	    	answer=((multi* seed + incr) % modu);
	    	seed=answer;
	    	return answer;	
	    }
	    
	    public double DivideModulus()
	    {
	    	divmod=GenerateNext() / (double) modu;
	    	return divmod;
	    }
	    
	    public static void main (String[] args)
	    {
	    	pseudorandom r= new pseudorandom (40, 36, 3641, 729);
	    	int [] count = new int []{0,0,0,0,0,0,0,0,0,0};
	    	for (int i=0; i < 1000000; i++){
	    	   	int answer=r.GenerateNext();
	    	   	double divmod=r.DivideModulus();
	    	   	//Which range is our value in?
	    	   	if (divmod >= 0.0 || divmod < 0.1)
	    	   	{
	    	   	 count [0] ++;
	    	   	}
	    	   	else if (divmod >= 0.1 || divmod < 0.2)
	    	   	{
	    	   		count [1] ++;
	    	   	}
	    	   	else if (divmod >= 0.2 || divmod < 0.3)
	    	   	{
	    	   		count [2] ++;
	    	   	}
	    	   	else if (divmod >= 0.3 || divmod < 0.4)
	    	   	{
	    	   		count [3] ++;
	    	   	}
	    	   	else if (divmod >= 0.4 || divmod < 0.5)
	    	   	{
	    	   		count [4] ++;
	    	   	}
	    	   	else if (divmod >= 0.5 || divmod < 0.6)
	    	   	{
	    	   		count [5] ++;
	    	   	}
	    	   	else if (divmod >= 0.6 || divmod < 0.7)
	    	   	{
	    	   		count [6] ++;
	    	   	}
	    	   	else if (divmod >= 0.7 || divmod < 0.8)
	    	   	{
	    	   		count [7] ++;
	    	   	}
	    	   	else if (divmod >= 0.8 || divmod < 0.9)
	    	   	{
	    	   		count [8] ++;
	    	   	}
	    	   	else if (divmod >= 0.9 || divmod < 1.0)
	    	   	{
	    	   		count [9] ++;
	    	   	}

		    	//System.out.println(answer);
		    	//System.out.println(divmod);
		    	
	    	}
	    	
	        System.out.println("Range        # of Occurances");
	        System.out.println("[0.0..0.1)       " + count [0]);
	        System.out.println("[0.1..0.2)       " + count [1]);
	        System.out.println("[0.2..0.3)       " + count [2]);
	        System.out.println("[0.3..0.4)       " + count [3]);
	        System.out.println("[0.4..0.5)       " + count [4]);
	        System.out.println("[0.5..0.6)       " + count [5]);
	        System.out.println("[0.6..0.7)       " + count [6]);
	        System.out.println("[0.7..0.8)       " + count [7]);
	        System.out.println("[0.8..0.9)       " + count [8]);
	        System.out.println("[0.9..1.0)       " + count [9]);
	    	
	    }




	}

The List is supposed to list how many times the number appears in a range but the output I get is this.
Range # of Occurances
[0.0..0.1) 1000000
[0.1..0.2) 0
[0.2..0.3) 0
[0.3..0.4) 0
[0.4..0.5) 0
[0.5..0.6) 0
[0.6..0.7) 0
[0.7..0.8) 0
[0.8..0.9) 0
[0.9..1.0) 0

all one million occurrences appear in one range instead of a mixture of different numbers in the different ranges. Can you help me?

if (divmod >= 0.0 || divmod < 0.1)

One of the above two conditions is always true. You wanted to use the && symbol.

if (divmod >= 0.0 && divmod < 0.1)
Comments
Very Helpful

now to change that code to actually match the coding standards.

  • class names should be in CamelCase with a starting capital
  • method names should be in camelCase without a starting capital
  • all classes should be inside a package
  • etc. etc. etc.
This article has been dead for over six months. Start a new discussion instead.