Math.random () produced by [0,1]!!! Double K=math.random ();//Note the following = to be added, so as to satisfy the mathematical symmetry if (k>=0.5)// This means that when the random number produced is greater than or equal to 0.5, say that own cow B, less than 0.5 said this own silly BSystem.out.println ("I live between cattle a and cattle C" +k); ElseSystem.out.println ("I live between silly a and silly C" +k) //===========================================================int a=13;int b=25;//premise is B>A!!! The method to produce an integer between [a, b] is (Math.random () * (b-a+1) +a)) int r = (int) (Math.random () * (b-a+1)) +a; System.out.println (R);//===========================================================//outputs the characters between 65--90 [A,z]for (int i = 0; I < 26; i++) {int c = (int) (Math.random () * (90-65+1) +65);//or * (z-a+1) +asystem.out.println ((char) c);//convert to corresponding ASCII character}
Random numbers in Java (Math.random ()), and how to produce a random number similar to the [21,77] interval.