@Test
  public void testCnxManagerTimeout() throws Exception {
    Random rand = new Random();
    byte b = (byte) rand.nextInt();
    int deadPort = PortAssignment.unique();
    String deadAddress = new String("10.1.1." + b);

    LOG.info("This is the dead address I'm trying: " + deadAddress);

    peers.put(
        Long.valueOf(2),
        new QuorumServer(
            2,
            new InetSocketAddress(deadAddress, deadPort),
            new InetSocketAddress(deadAddress, PortAssignment.unique())));
    peerTmpdir[2] = ClientBase.createTmpDir();

    QuorumPeer peer =
        new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 1000, 2, 2);
    QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
    QuorumCnxManager.Listener listener = cnxManager.listener;
    if (listener != null) {
      listener.start();
    } else {
      LOG.error("Null listener when initializing cnx manager");
    }

    long begin = System.currentTimeMillis();
    cnxManager.toSend(new Long(2), createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));
    long end = System.currentTimeMillis();

    if ((end - begin) > 6000) fail("Waited more than necessary");
  }
  @LargeTest
  public void testManyRowsTxtLong() throws Exception {
    mDatabase.execSQL("CREATE TABLE test (_id INTEGER PRIMARY KEY, txt TEXT, data INT);");

    Random random = new Random(System.currentTimeMillis());
    StringBuilder randomString = new StringBuilder(1979);
    for (int i = 0; i < 1979; i++) {
      randomString.append((random.nextInt() & 0xf) % 10);
    }

    // if cursor window size changed, adjust this value too
    final int count = 600;
    for (int i = 0; i < count; i++) {
      StringBuilder sql = new StringBuilder(2100);
      sql.append("INSERT INTO test (txt, data) VALUES ('");
      sql.append(randomString);
      sql.append("','");
      sql.append(i);
      sql.append("');");
      mDatabase.execSQL(sql.toString());
    }

    Cursor c = mDatabase.query("test", new String[] {"txt", "data"}, null, null, null, null, null);
    assertNotNull(c);

    int i = 0;
    while (c.moveToNext()) {
      assertEquals(randomString.toString(), c.getString(0));
      assertEquals(i, c.getInt(1));
      i++;
    }
    assertEquals(count, i);
    assertEquals(count, c.getCount());
    c.close();
  }
  @MediumTest
  public void testLargeField() throws Exception {
    mDatabase.execSQL("CREATE TABLE test (_id INTEGER PRIMARY KEY, data TEXT);");

    StringBuilder sql = new StringBuilder(2100);
    sql.append("INSERT INTO test (data) VALUES ('");
    Random random = new Random(System.currentTimeMillis());
    StringBuilder randomString = new StringBuilder(1979);
    for (int i = 0; i < 1979; i++) {
      randomString.append((random.nextInt() & 0xf) % 10);
    }
    sql.append(randomString);
    sql.append("');");
    mDatabase.execSQL(sql.toString());

    Cursor c = mDatabase.query("test", null, null, null, null, null, null);
    assertNotNull(c);
    assertEquals(1, c.getCount());

    assertTrue(c.moveToFirst());
    assertEquals(0, c.getPosition());
    String largeString = c.getString(c.getColumnIndexOrThrow("data"));
    assertNotNull(largeString);
    assertEquals(randomString.toString(), largeString);
    c.close();
  }
  /**
   * Method that generates POIs with red markers and random geoposition
   *
   * @param context
   * @return array list of POIs
   */
  public ArrayList<ExamplePoiModel> getRedArray(Context context) {

    Random randomObject = new Random();
    ArrayList<ExamplePoiModel> poisArray = new ArrayList<ExamplePoiModel>();
    ExamplePoiModel poiObject;

    for (int i = 0; i < NUM_POIS / 2; i++) {

      int latE6 = (int) ((randomObject.nextFloat() * GEO_MAX * 2) - GEO_MAX);
      int lonE6 = (int) ((randomObject.nextFloat() * GEO_MAX * 2) - GEO_MAX);
      GeoPoint randomGeoPoint = new GeoPoint(latE6, lonE6);

      Drawable customMarker = context.getResources().getDrawable(R.drawable.poi_red);
      customMarker.setBounds(
          0, 0, customMarker.getIntrinsicWidth(), customMarker.getIntrinsicHeight());

      poiObject = new ExamplePoiModel();
      poiObject.setGeoPoint(randomGeoPoint);
      poiObject.setMarkerDrawable(customMarker);
      poiObject.setTitle("Red #" + i);
      poiObject.setSnippet(
          "Position: "
              + randomGeoPoint.getLatitudeE6() / 1E6
              + ", "
              + randomGeoPoint.getLongitudeE6() / 1E6);

      poisArray.add(poiObject);
    }
    return poisArray;
  }
示例#5
0
  public static void main(String[] args) {
    List<Map<String, Integer>> list = new ArrayList<Map<String, Integer>>();
    for (int i = 24; i <= 28; i++) {
      Map<String, Integer> map = new HashMap<String, Integer>();
      map.put("day", i);
      map.put("havedata", 0);
      list.add(map);
    }
    Random r = new Random();
    for (int i = 1; i <= 31; i++) {
      Map<String, Integer> map = new HashMap<String, Integer>();
      map.put("day", i);
      map.put("havedata", 1);
      map.put("nowfee", 3216 + r.nextInt(1000000));
      map.put("oldfee", 3216 + r.nextInt(1000000));
      map.put("dau", 3216 + r.nextInt(1000000));
      map.put("dnu", 3216 + r.nextInt(1000000));
      list.add(map);
    }
    for (int i = 1; i <= 6; i++) {
      Map<String, Integer> map = new HashMap<String, Integer>();
      map.put("day", i);
      map.put("havedata", 0);
      list.add(map);
    }
    System.out.println(array2JsonString(list));

    String json =
        "{\"code\":0,\"info\":\"success\",\"data\":{\"systemMail\":{\"mailVer\":19,\"target\":0,\"condition\":0,\"value\":2,\"title\":\"???è?????é??\",\"content\":\"???è?????é?????è?????é??\",\"sendTime\":1402555848,\"award\":{\"awardId\":0,\"gold\":2,\"heart\":2,\"diamond\":333,\"items\":[12,123],\"itemsCount\":[1,2]}}},\"sys_time\":1402555848}";
    JSONObject obj = getObj(json);
    System.out.println(obj.getJSONObject("data").getJSONObject("systemMail").getInt("mailVer"));
    System.out.println(obj.getInt("code"));
  }
示例#6
0
 /** java.util.Random#setSeed(long) */
 public void test_setSeedJ() {
   // Test for method void java.util.Random.setSeed(long)
   long[] randomArray = new long[100];
   boolean someDifferent = false;
   final long firstSeed = 1000;
   long aLong, anotherLong, yetAnotherLong;
   Random aRandom = new Random();
   Random anotherRandom = new Random();
   Random yetAnotherRandom = new Random();
   aRandom.setSeed(firstSeed);
   anotherRandom.setSeed(firstSeed);
   for (int counter = 0; counter < randomArray.length; counter++) {
     aLong = aRandom.nextLong();
     anotherLong = anotherRandom.nextLong();
     assertTrue(
         "Two randoms with same seeds gave differing nextLong values", aLong == anotherLong);
     yetAnotherLong = yetAnotherRandom.nextLong();
     randomArray[counter] = aLong;
     if (aLong != yetAnotherLong) someDifferent = true;
   }
   assertTrue("Two randoms with the different seeds gave the same chain of values", someDifferent);
   aRandom.setSeed(firstSeed);
   for (int counter = 0; counter < randomArray.length; counter++)
     assertTrue(
         "Reseting a random to its old seed did not result in the same chain of values as it gave before",
         aRandom.nextLong() == randomArray[counter]);
 }
示例#7
0
 @Override
 public void populate(Chunk chunk, Random random) {
   if (chunk.getY() != 4) {
     return;
   }
   final World world = chunk.getWorld();
   if (random.nextInt(WATER_ODD) == 0) {
     final int x = chunk.getBlockX(random);
     final int z = chunk.getBlockZ(random);
     final int y = random.nextInt(128);
     WATER_POND.setRandom(random);
     WATER_POND.randomize();
     if (WATER_POND.canPlaceObject(world, x, y, z)) {
       WATER_POND.placeObject(world, x, y, z);
     }
   }
   if (random.nextInt(LAVA_ODD) == 0) {
     final int x = chunk.getBlockX(random);
     final int z = chunk.getBlockZ(random);
     final int y = random.nextInt(120) + 8;
     if (y >= 63 && random.nextInt(LAVA_SURFACE_ODD) != 0) {
       return;
     }
     LAVA_POND.setRandom(random);
     LAVA_POND.randomize();
     if (LAVA_POND.canPlaceObject(world, x, y, z)) {
       LAVA_POND.placeObject(world, x, y, z);
     }
   }
 }
示例#8
0
  byte[] randomLargeData(int bs) {
    Random r = new Random();
    byte[] ret = new byte[bs];

    r.nextBytes(ret);
    return ret;
  }
  int getValues(Map<String, Object> values, String ip, String timeout) {
    try {
      Class.forName("edu.bucknell.net.JDHCP.DHCPSocket");
    } catch (ClassNotFoundException cnfe) {
      lastError = "JDHCP libraries unavailable (see Help document for DHCP Monitor)";
      return 1;
    }

    IP = ip;
    Timeout = Integer.parseInt(timeout);

    int sleepTime = 1000;
    Random r = new Random();
    int xid = r.nextInt();
    byte hwaddr[] = new byte[16];

    startTime = System.currentTimeMillis();
    Object results[] = acquireAddress(xid, hwaddr, sleepTime);
    if (results[0].equals("n/a")) {
      lastError = (String) results[4];
      return 1;
    } else {
      values.put("Roundtime", results[1]);
      values.put("Address", results[4]);
    }

    return 0;
  }
示例#10
0
 @Test
 // The following test is on a relatively large unsorted list filled with random numbers allowing
 // duplicated elements.
 public void testAllSecond() {
   // Make a random target list.
   int s = 1000;
   int[] target = new int[s];
   Random rand = new Random(System.currentTimeMillis());
   for (int i = 0; i < target.length; i++) target[i] = rand.nextInt(s / 2);
   // Sort the resulting list with each sorting algorithm.
   MergeSort ms = new MergeSort(target);
   QuickSort qs = new QuickSort(target);
   HeapSort hs = new HeapSort(target);
   int[] mr = ms.sort(MergeSort.ASC_DESC.DESCENDING);
   int[] qr = qs.sort(QuickSort.ASC_DESC.DESCENDING);
   int[] hr = hs.sort(HeapSort.ASC_DESC.DESCENDING);
   // Compare the results.
   /*for (int i = 0; i < target.length; i++)
   {
   	assertEquals(mr[i], qr[i]);
   	assertEquals(qr[i], hr[i]);
   }*/
   assertArrayEquals(mr, qr);
   assertArrayEquals(qr, hr);
 }
示例#11
0
    private void setSpeedAndDirection(Random r) {

      // Used by test cases
      switch (speedMode) {
        case SINGLE:
          mDx = 500;
          mDy = 500;
          break;

        case STILL:

          // No speed
          mDx = 0;
          mDy = 0;
          break;

        default:

          // Set mDx and mDy to indicate movement direction and speed
          // Limit speed in the x and y direction to [-3..3] pixels per movement.

          mDx = (r.nextBoolean() ? -1 : 1) * r.nextInt(5);
          mDy = (r.nextBoolean() ? -1 : 1) * r.nextInt(5);
      }
    }
示例#12
0
  @Deprecated
  private List<String> allocateSubject() {
    // init test data
    List<String> mList = new ArrayList<String>();
    String g = "语文";
    mList.add(g);

    g = "数学";
    mList.add(g);

    g = "英语";
    mList.add(g);

    g = "化学";
    mList.add(g);

    g = "政治";
    mList.add(g);

    g = "物理";
    mList.add(g);

    g = "英语";
    mList.add(g);
    for (int i = 0; i < 3; i++) {
      Random random = new Random();
      int d = random.nextInt(7 - i);
      mList.remove(d);
    }
    return mList;
  }
 private void appendRandomChars(StringBuilder str, char[] chars, int minlen, int maxlen) {
   int len = rand.nextInt(maxlen - minlen) + minlen;
   int charsLen = chars.length;
   for (int i = 0; i < len; i++) {
     str.append(chars[rand.nextInt(charsLen)]);
   }
 }
  @Override
  public synchronized void run() {
    try {
      // print header
      inputBuffer.put("<h>sysTime\tBattV\tCurrent\tDutyCycle\tCadence\tGenSpeed\tconst</h>");
      inputBuffer.put("<u>s\tmillivolts\tmilliamps\tpercent\thz\thz\tconst</u>");
    } catch (Exception ex) {

    }
    while (!quit) {
      counter++;
      float battV = rndGen.nextFloat() * 3 + 12;
      float current = rndGen.nextFloat() * 3 + -1001;
      float dutyCycle = rndGen.nextFloat() * 50 + 50;
      float cadence = rndGen.nextFloat() * (float) (.2) - (float) (.1);
      float genSpeed = rndGen.nextFloat() * 250 + 10000;
      try {
        Thread.sleep(100);
        inputBuffer.put(
            String.format(
                "<r>%.3f\t%.3f\t%.3f\t%.3f\t%.3f\t" + "%.3f\t%d</r>",
                (float) time / 1000.0, battV, current, dutyCycle, cadence, genSpeed, 5));
        if (counter % 10 == 0) inputBuffer.put("<m>message at row " + counter + "</m>");
      } catch (Exception e) {
        System.out.print("\nin testSerialInput\n");
      }
      time += 100;
    }
  }
  @Override
  public void generate(
      Random rand,
      int chunkX,
      int chunkZ,
      World world,
      IChunkProvider chunkGenerator,
      IChunkProvider chunkProvider) {
    chunkX = chunkX << 4;
    chunkZ = chunkZ << 4;
    final BiomeGenBase biome = world.getBiomeGenForCoords(chunkX, chunkZ);

    if (BiomeSettings.GREENSWAMP.getBiome().isPresent()
            && biome == BiomeSettings.GREENSWAMP.getBiome().get()
        || BiomeSettings.MOUNTAINRIDGE.getBiome().isPresent()
            && biome == BiomeSettings.MOUNTAINRIDGE.getBiome().get()
        || BiomeSettings.REDWOODLUSH.getBiome().isPresent()
            && biome == BiomeSettings.REDWOODLUSH.getBiome().get()
        || BiomeSettings.WOODLANDS.getBiome().isPresent()
            && biome == BiomeSettings.WOODLANDS.getBiome().get())
      for (int i = 0; i < 2; i++) {
        final int x = chunkX + rand.nextInt(16) + 8;
        final int y = rand.nextInt(128);
        final int z = chunkZ + rand.nextInt(16) + 8;
        leafPileGen.generate(world, rand, x, y, z);
      }
  }
 /**
  * Случайно генерируются значения списка
  *
  * @param count Количество значений
  */
 public LinkedListVector(int count) {
   this();
   for (int i = 0; i < count; i++) {
     Random xd = new Random();
     addElement(Math.ceil(xd.nextDouble() * 15));
   }
 }
  public void testRandomAccess() throws DerivativeException, IntegratorException {

    ContinuousOutputModel cm = new ContinuousOutputModel();
    integ.setStepHandler(cm);
    integ.integrate(
        pb,
        pb.getInitialTime(),
        pb.getInitialState(),
        pb.getFinalTime(),
        new double[pb.getDimension()]);

    Random random = new Random(347588535632l);
    double maxError = 0.0;
    for (int i = 0; i < 1000; ++i) {
      double r = random.nextDouble();
      double time = r * pb.getInitialTime() + (1.0 - r) * pb.getFinalTime();
      cm.setInterpolatedTime(time);
      double[] interpolatedY = cm.getInterpolatedState();
      double[] theoreticalY = pb.computeTheoreticalState(time);
      double dx = interpolatedY[0] - theoreticalY[0];
      double dy = interpolatedY[1] - theoreticalY[1];
      double error = dx * dx + dy * dy;
      if (error > maxError) {
        maxError = error;
      }
    }

    assertTrue(maxError < 1.0e-9);
  }
示例#18
0
  private static void sendSimpleEmails(String toUserName, int count)
      throws MessagingException, InterruptedException, IOException {

    Session session = Session.getInstance(getEmailProperties());

    Random random = new Random();
    int emailSize = emails.length;
    for (int i = 1; i <= count; i++) {
      Thread.sleep(10000);

      MimeMessage msg = new MimeMessage(session);

      InternetAddress from = new InternetAddress(emails[random.nextInt(emailSize)]);

      InternetAddress to = new InternetAddress(toUserName);

      msg.setFrom(from);
      msg.addRecipient(Message.RecipientType.TO, to);
      msg.setSentDate(new Date());

      SimpleMessage randomMessage =
          SimpleMessage.values()[random.nextInt(SimpleMessage.values().length)];
      msg.setSubject(randomMessage.name());
      msg.setText(randomMessage.getBody());
      Transport.send(msg);
    }
  }
 public String[] receiveTransactionId(byte[] data)
     throws RemoteException, InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException,
         IllegalBlockSizeException, BadPaddingException {
   Cipher cipher = Cipher.getInstance("RSA");
   cipher.init(Cipher.DECRYPT_MODE, privateKey);
   byte[] cipherData = cipher.doFinal(data);
   String x = new String(cipherData);
   System.out.println(x);
   if (x.equals("e3050620f38846eeab342d293f13e043")) {
     String val = UUID.randomUUID().toString().replaceAll("-", "");
     transactionDetails[0] = val;
     System.out.println(transactionDetails[0]);
     String bits = "";
     Random r = new Random();
     for (int l = 0; l < 2048; l++) {
       int y = 0;
       if (r.nextBoolean()) y = 1;
       bits += y;
     }
     transactionDetails[1] = bits;
     System.out.println(transactionDetails[1]);
     System.out.println(transactionDetails);
   }
   return transactionDetails;
 }
  @Override
  public Xid createTransactionIdentifier() {
    Random random = new Random(System.currentTimeMillis());

    final int formatId = random.nextInt();
    final byte[] globalTransactionId = new byte[Xid.MAXGTRIDSIZE];
    random.nextBytes(globalTransactionId);
    final byte[] branchQualifier = new byte[Xid.MAXBQUALSIZE];
    random.nextBytes(branchQualifier);

    return new Xid() {
      @Override
      public int getFormatId() {
        return formatId;
      }

      @Override
      public byte[] getGlobalTransactionId() {
        return globalTransactionId;
      }

      @Override
      public byte[] getBranchQualifier() {
        return branchQualifier;
      }
    };
  }
示例#21
0
  /*
   * メインメソッド
   *
   * @param 実行時の引数
   */
  public static void main(String[] args) {

    System.out.println("じゃんけんをしましょう!");
    System.out.println("1:グー、 2:チョキ 3:パー");
    int userHand = 0;
    Random rdm = new Random();

    // ユーザの手の入力
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    boolean isFinish = false;
    while (!isFinish) {
      try {
        // コンピュータの手(ランダム)
        int comHandNum = rdm.nextInt(3) + 1;
        // ユーザの手(入力)
        String str = br.readLine();
        userHand = Integer.parseInt(str);
        // 正しい入力範囲かの確認
        if (userHand == ROCK_NUM || userHand == PAPER_NUM || userHand == SCISSORS_NUM) {
          // 出した手を確認
          System.out.println(
              "あなたは:" + getHandName(userHand) + " コンピュータは:" + getHandName(comHandNum));
          // 終了と勝ち負けの判定
          isFinish = isNotDraw(userHand, comHandNum);
        } else {
          System.out.println("1〜3で入力してください!");
        }
      } catch (NumberFormatException e) {
        System.out.println("1〜3で入力してください!");
      } catch (IOException e) {
        System.out.println("予期せぬエラーが発生しました");
        return;
      }
    }
  }
示例#22
0
 public void run() {
   BufferedImage img = panel.getImage();
   Graphics2D g2 = img.createGraphics();
   int anzahl = 255;
   int st = 6;
   int r = st / 2;
   int x1, y1;
   int c;
   Random random = new Random();
   MyColor myColor = MyColor.getInstance();
   for (int y = 0; y < img.getHeight(); y += st) {
     for (Integer x = 0; x < img.getWidth(); x += st) {
       int color = img.getRGB(x, y);
       if (color != RED && color != WHITE) {
         c = 0;
         for (int i = 0; i < anzahl; i++) {
           x1 = x;
           y1 = y;
           color = BLACK;
           while (color != RED && color != WHITE) {
             x1 += random.nextBoolean() ? 5 : -5;
             y1 += random.nextBoolean() ? 5 : -5;
             color = img.getRGB(x1, y1);
           }
           if (color == RED) {
             c += 1;
           }
         }
         System.out.println("Point(" + x + "," + y + ")  c=" + c);
         g2.setColor(myColor.getColorAt(c));
         g2.fillOval(x - r, y - r, st, st);
       }
     }
   }
 }
示例#23
0
    public void paint(Graphics g) {
      Graphics2D g2d = (Graphics2D) g;
      ArrayList<Color> colors = new ArrayList<>();
      colors.add(Color.red);
      colors.add(Color.blue);
      colors.add(Color.green);
      colors.add(Color.orange);
      colors.add(Color.yellow);
      colors.add(Color.magenta);
      colors.add(Color.cyan);
      colors.add(Color.pink);

      Random r = new Random();
      g2d.setColor(Color.white);
      Shape yAxis = new Line2D.Double(950, 1920, 950, 0);
      Shape xAxis = new Line2D.Double(0, 540, 1920, 540);
      g2d.draw(yAxis);
      g2d.draw(xAxis);
      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

      if (var != null) {

        /*for (int s = count; s < theG.size(); s++){
        	g2d.setColor(colors.get(r.nextInt(8)));
        	g2d.fill(theG.get(s));
        	count = count + 1;
        }*/

        for (Shape s : theG) {
          g2d.setColor(colors.get(r.nextInt(8)));
          g2d.fill(s);
        }
      }
    }
 public void testRandom() throws Exception {
   if (IGNORE_LOAD_TESTS) {
     return;
   }
   int input = 1000;
   initResequencer(1000, 1000);
   List<Integer> list = new LinkedList<Integer>();
   for (int i = 0; i < input; i++) {
     list.add(i);
   }
   Random random = new Random(System.currentTimeMillis());
   System.out.println("Input sequence:");
   long millis = System.currentTimeMillis();
   for (int i = input; i > 0; i--) {
     int r = random.nextInt(i);
     int next = list.remove(r);
     System.out.print(next + " ");
     resequencer.insert(next);
   }
   System.out.println("\nOutput sequence:");
   for (int i = 0; i < input; i++) {
     System.out.print(buffer.take() + " ");
   }
   millis = System.currentTimeMillis() - millis;
   System.out.println("\nDuration = " + millis + " ms");
 }
示例#25
0
  static synchronized Random getRandom(String algorithm, Double seed) throws ExpressionException {

    algorithm = algorithm.toLowerCase();

    Random result = randoms.get(algorithm);

    if (result == null || !seed.isNaN()) {
      if (CFMXCompat.ALGORITHM_NAME.equalsIgnoreCase(algorithm)) {

        result = new Random();
      } else {

        try {

          result = SecureRandom.getInstance(algorithm);
        } catch (NoSuchAlgorithmException e) {
          throw new ExpressionException(
              "random algorithm [" + algorithm + "] is not installed on the system",
              e.getMessage());
        }
      }

      if (!seed.isNaN()) result.setSeed(seed.longValue());

      randoms.put(algorithm, result);
    }

    return result;
  }
示例#26
0
  /**
   * Calculate the next alarm time for overdue reminders.
   *
   * <p>We schedule an alarm for after the due date (which could be in the past), with the exception
   * that if a reminder was recently issued, we move the alarm time to the near future.
   *
   * @param task
   * @return
   */
  private long calculateNextOverdueReminder(Task task) {
    // Uses getNowValue() instead of DateUtilities.now()
    if (task.hasDueDate() && task.getFlag(Task.REMINDER_FLAGS, Task.NOTIFY_AFTER_DEADLINE)) {
      Date due = new Date(task.getValue(Task.DUE_DATE));
      if (!task.hasDueTime()) {
        due.setHours(23);
        due.setMinutes(59);
        due.setSeconds(59);
      }
      long dueDateForOverdue = due.getTime();
      long lastReminder = task.getValue(Task.REMINDER_LAST);

      if (dueDateForOverdue > getNowValue()) {
        return dueDateForOverdue
            + (long) ((0.5f + 2f * random.nextFloat()) * DateUtilities.ONE_HOUR);
      }

      if (lastReminder < dueDateForOverdue) {
        return getNowValue();
      }

      if (getNowValue() - lastReminder < 6 * DateUtilities.ONE_HOUR) {
        return getNowValue()
            + (long)
                ((2.0f + task.getValue(Task.IMPORTANCE) + 6f * random.nextFloat())
                    * DateUtilities.ONE_HOUR);
      }

      return getNowValue();
    }
    return NO_ALARM;
  }
示例#27
0
 private int getRandomColor() {
   Random randomGenerator = new Random();
   int red = randomGenerator.nextInt(255);
   int green = randomGenerator.nextInt(255);
   int blue = randomGenerator.nextInt(255);
   return Color.rgb(red, green, blue);
 }
 public void generateStructures(World world, Random rand, BlockPos position, int radius) {
   for (int i = 0; radius >= 0 && i < 3; ++i) {
     int j = radius + rand.nextInt(2);
     int k = (radius + rand.nextInt(2));
     int l = radius + rand.nextInt(2);
     float f = (float) (j + k + l) * 0.333F + 0.5F;
     for (BlockPos blockpos :
         BlockPos.getAllInBox(position.add(-j, -k, -l), position.add(j, k, l))) {
       if (blockpos.distanceSq(position) <= (double) (f * f)
           && world.isAirBlock(blockpos)
           && world
               .getBlockState(blockpos.down())
               .getBlock()
               .getUnlocalizedName()
               .contains("frozen")) {
         int chance = rand.nextInt(100);
         if (chance < 4) {
           int chance2 = rand.nextInt(20);
           System.out.println(chance2);
           switch (chance2) {
             default:
               generateGoldPile(world, rand, blockpos);
               break;
             case 1:
               generateArchNS(world, rand, blockpos);
               break;
             case 2:
               generateArchEW(world, rand, blockpos);
               break;
           }
         }
       }
     }
   }
 }
示例#29
0
 /*    */ public static String getName() /*    */ {
   /* 19 */ Random rnd = new Random();
   /* 20 */ String name =
       firstNames[rnd.nextInt(firstNameLength)] + secondNames[rnd.nextInt(secondNameLength)];
   /*    */
   /* 22 */ return name;
   /*    */ }
示例#30
0
  @Override
  public void randomDisplayTick(World par1World, int x, int y, int z, Random par5Random) {
    TileEntity tile = par1World.getBlockTileEntity(x, y, z);

    if (tile instanceof GCCoreTileEntityCoalGenerator) {
      GCCoreTileEntityCoalGenerator tileEntity = (GCCoreTileEntityCoalGenerator) tile;
      if (tileEntity.generateWatts > 0) {
        int metadata = par1World.getBlockMetadata(x, y, z);
        float var7 = x + 0.5F;
        float var8 = y + 0.0F + par5Random.nextFloat() * 6.0F / 16.0F;
        float var9 = z + 0.5F;
        float var10 = 0.52F;
        float var11 = par5Random.nextFloat() * 0.6F - 0.3F;

        if (metadata == 3) {
          par1World.spawnParticle("smoke", var7 - var10, var8, var9 + var11, 0.0D, 0.0D, 0.0D);
          par1World.spawnParticle("flame", var7 - var10, var8, var9 + var11, 0.0D, 0.0D, 0.0D);
        } else if (metadata == 2) {
          par1World.spawnParticle("smoke", var7 + var10, var8, var9 + var11, 0.0D, 0.0D, 0.0D);
          par1World.spawnParticle("flame", var7 + var10, var8, var9 + var11, 0.0D, 0.0D, 0.0D);
        } else if (metadata == 1) {
          par1World.spawnParticle("smoke", var7 + var11, var8, var9 - var10, 0.0D, 0.0D, 0.0D);
          par1World.spawnParticle("flame", var7 + var11, var8, var9 - var10, 0.0D, 0.0D, 0.0D);
        } else if (metadata == 0) {
          par1World.spawnParticle("smoke", var7 + var11, var8, var9 + var10, 0.0D, 0.0D, 0.0D);
          par1World.spawnParticle("flame", var7 + var11, var8, var9 + var10, 0.0D, 0.0D, 0.0D);
        }
      }
    }
  }