Guest User

BestRandom

a guest
Mar 11th, 2019
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. import java.lang.Math;
  2.  
  3. public class BestRandom
  4. {
  5.   public static void main(String[] args)
  6.   {
  7.     BestRandom r = new BestRandom();
  8.     int o1 = r.random_int(0,99);
  9.     System.out.println(o1);
  10.     int o2 = r.random_int(0,99);
  11.     System.out.println(o2);
  12.   }
  13.  
  14.     private static int random_int(int l, int u) {
  15.       int n = (int) System.currentTimeMillis();
  16.       int length = (int) (Math.log10(u) + 1);
  17.  
  18.       while(true){
  19.         //get last length number of digits from n
  20.         int t = n % ((int) Math.pow(10, length));
  21.         if(t<u && t>l)
  22.           return t;
  23.         else
  24.           n = (int) System.currentTimeMillis();
  25.       }
  26.      
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment