Exemplo n.º 1
0
 private float[] calculateTimeToHomeRate(TimeToGoHome timeToGoHome) {
   if (timeToGoHome == null || timeToGoHome.isEmpty()) {
     return NumUtils.newEmptyFloatArray(RANGE_DIVIDER);
   }
   final int testCount = timeToGoHome.getTestCount();
   final int range = testCount / RANGE_DIVIDER;
   final int[] occ = NumUtils.newEmptyIntArray(RANGE_DIVIDER);
   for (int i = 0; i < timeToGoHome.size(); i++) {
     final int index = timeToGoHome.get(i) / range;
     occ[index]++;
   }
   return NumUtils.calculateProbability(occ);
 }
Exemplo n.º 2
0
  private List<SimpleLottery> getAllLotteries(Lottery.Type type, boolean noFilter) {
    final LotteryConfiguration configuration = LotteryConfiguration.getWithType(type);
    List<List<Integer>> normals =
        NumUtils.exhaustC(configuration.getNormalRange(), configuration.getNormalSize());
    List<List<Integer>> specials =
        NumUtils.exhaustC(configuration.getSpecialRange(), configuration.getSpecialSize());
    List<SimpleLottery> allLotteries = new ArrayList<>(normals.size() * specials.size());
    System.out.println(
        "calculateAndSave integers finished! all size: " + normals.size() * specials.size());
    for (int i = 0; i < specials.size(); i++) {
      for (int j = 0; j < normals.size(); j++) {
        final SimpleLottery simpleLottery = new SimpleLottery(normals.get(j), specials.get(i));
        if (noFilter) {
          allLotteries.add(simpleLottery);
        } else if (!hasTooMuchSequence(normals.get(j), type)) {
          int sum = sum(simpleLottery);
          int odd = odd(normals.get(j));
          if (type == Lottery.Type.DLT) {
            // dlt 从57 < sum < 157
            if (sum >= 157 || sum <= 57) {
              continue;
            }
          } else {
            // ssq 从63 < sum < 161
            if (sum >= 161 || sum <= 63) {
              continue;
            }
          }

          allLotteries.add(simpleLottery);
        }
      }
    }
    System.out.println("all lotteries ready: size: " + allLotteries.size());
    return allLotteries;
  }
Exemplo n.º 3
0
 public List<Lottery> select(List<Lottery> tempBuffer, int count, TimeToGoHome timeToGoHome) {
   if (tempBuffer == null || count < 0 || count > tempBuffer.size()) {
     return null;
   }
   float[] rate = calculateTimeToHomeRate(timeToGoHome);
   tempBuffer = filterTempBuffer(tempBuffer);
   final List<Lottery> result = new ArrayList<>();
   for (int i = 0; i < count; i++) {
     final int startIndex =
         NumUtils.calculateIndexWithWeight(rate, com.qqdd.lottery.utils.Random.getInstance());
     final int range = tempBuffer.size() / rate.length;
     final int startFrom = startIndex * range;
     final int index = com.qqdd.lottery.utils.Random.getInstance().nextInt(range) + startFrom;
     System.out.println("selected index: " + index);
     result.add(tempBuffer.get(index % tempBuffer.size()));
     //        for (int i = 0; i < count; i++) {
     //            result.add(tempBuffer.get((index + i) % tempBuffer.size()));
     //        }
   }
   return result;
 }