Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.lang.Math;
- public class BestRandom
- {
- public static void main(String[] args)
- {
- BestRandom r = new BestRandom();
- int o1 = r.random_int(0,99);
- System.out.println(o1);
- int o2 = r.random_int(0,99);
- System.out.println(o2);
- }
- private static int random_int(int l, int u) {
- int n = (int) System.currentTimeMillis();
- int length = (int) (Math.log10(u) + 1);
- while(true){
- //get last length number of digits from n
- int t = n % ((int) Math.pow(10, length));
- if(t<u && t>l)
- return t;
- else
- n = (int) System.currentTimeMillis();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment