Pure random number generator, and the problem of overloaded functions

  • Achieved by generating a random number of handwritten code

         official:

          

         

 

 

          Means that the formula x (n + 1) = (16807 * x (n))% 2 ^ 31-1

 

 

 

          code show as below:

Package javatask; 

Import java.util.Random;
 Import java.util.Scanner; 

public  class random1 {
     static Scanner in = new new Scanner (the System.in); 
    
    static  public  void Seed ( Long SEED) 
    { 
        the Random RAND = new new the Random ();
         Long a, X = 0 , X1; 
        System.out.println ( "Please enter the number of the random number generated want" ); 
        a = in.nextLong ();
         for ( Long I =. 1; I <= a; ++ I ) 
        {
            X1 = (16800 * SEED)% (Integer.MAX_VALUE); 
            System.out.println (X1); 
            X ++ ;
             IF (X <= (32 + 2E) -2 ) 
                SEED = X1;
             the else 
                SEED = rand.nextLong (); 
        } 
        
    } 
    public  static  void main (String [] args) 
    { 
        Long B; 
        System.out.println ( "Please enter the desired seed" ); 
        B = in.nextLong (); 
        seed (B); 
    } 
}
  • About function overloading

         1. the following two conditions can constitute a function overloading

            ① the same method name

            ② different types of parameters, number of different parameters, the parameter type sequence

            Note that the return value of the function types can not be judged as a condition of overloaded functions: because at runtime, not initially know what the called function return value is only beginning to find the corresponding function parameters depending on the type of

          2. Code:

            

package javaclass2;
// MethodOverload.java
// Using overloaded methods

public class MethodOverload {

    public static void main(String[] args) {
        System.out.println("The square of integer 7 is " + square(7));
        System.out.println("\nThe square of double 7.5 is " + square(7.5));
    }

    public static int square(int x) {
        return x * x;
    }

    public static double square(doubley) {
         return y * y; 
    } 
}

       Screenshot:

       

 

 

 

Guess you like

Origin www.cnblogs.com/xp-thebest/p/11587934.html