红包随机方法修改
parent
f4cd55beb5
commit
0d5dd5811f
|
@ -1,6 +1,7 @@
|
||||||
package com.ljsd.jieling.logic.family;
|
package com.ljsd.jieling.logic.family;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
public class HongBaoAlgorithm {
|
public class HongBaoAlgorithm {
|
||||||
static Random random = new Random();
|
static Random random = new Random();
|
||||||
|
@ -119,15 +120,25 @@ public class HongBaoAlgorithm {
|
||||||
}
|
}
|
||||||
|
|
||||||
static long sqr(long n) {
|
static long sqr(long n) {
|
||||||
// 查表快,还是直接算快?
|
// 查表快,还是直接算快? 50000--100000 2 ->50000
|
||||||
return n * n;
|
return n * n;
|
||||||
}
|
}
|
||||||
|
|
||||||
static long nextLong(long n) {
|
static long nextLong(long n) {
|
||||||
return random.nextInt((int) n);
|
// //50000*50000 = 25....>int
|
||||||
}
|
// if(n<Integer.MAX_VALUE){
|
||||||
|
// return random.nextInt((int) n);
|
||||||
|
// }
|
||||||
|
// long result = 0;
|
||||||
|
// while(n>Integer.MAX_VALUE){
|
||||||
|
// result+=random.nextInt(Integer.MAX_VALUE);
|
||||||
|
// }
|
||||||
|
return ThreadLocalRandom.current().nextLong(n);
|
||||||
|
}
|
||||||
|
|
||||||
static long nextLong(long min, long max) {
|
static long nextLong(long min, long max) {
|
||||||
return random.nextInt((int) (max - min + 1)) + min;
|
// return random.nextInt((int) (max - min + 1)) + min;
|
||||||
|
return ThreadLocalRandom.current().nextLong(max - min + 1)+min;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue