// Called by the UI when it wants to start over. // public void reset() { prn.setSeed(sd); minx = Integer.MAX_VALUE; miny = Integer.MAX_VALUE; maxx = Integer.MIN_VALUE; maxy = Integer.MIN_VALUE; pointHash.clear(); // empty out the set of points for (int i = 0; i < n; i++) { point p; int x; int y; do { x = prn.nextInt(); y = prn.nextInt(); p = new point(x, y); } while (pointHash.contains(p)); pointHash.add(p); if (x < minx) minx = x; if (y < miny) miny = y; if (x > maxx) maxx = x; if (y > maxy) maxy = y; points[i] = p; } edges.clear(); // empty out the set of edges }
public TreeNode getRandomNode() { int leftSize = left == null ? 0 : left.size(); Random random = new Random(); int index = random.nextInt(size); if (index == leftSize) return this; else if (index < leftSize) return left.getRandomNode(); else return right.getRandomNode(); }
public static void generateCFG(Vertex vertex[], int maxsucc, Random r) { int i; int j; int k; int s; // number of successors of a vertex. System.out.println("generating CFG..."); connect(vertex[0], vertex[1]); connect(vertex[0], vertex[2]); for (i = 2; i < vertex.length; ++i) { s = (r.nextInt() % maxsucc) + 1; for (j = 0; j < s; ++j) { k = Math.abs(r.nextInt()) % vertex.length; connect(vertex[i], vertex[k]); } } }
public LelyFeed(String host, int port) { this.channelListeners = new HashMap<String, Set<LelyFeedListener>>(); this.host = host; this.port = port; this.nick = "samza-bot-" + Math.abs(random.nextInt()); this.conn = new IRCConnection(host, new int[] { port }, "", nick, nick, nick); this.conn.addIRCEventListener(new LelyFeedIrcListener()); this.conn.setEncoding("UTF-8"); this.conn.setPong(true); this.conn.setColors(false); }
public float runTests(int num) { // run num indipendent tests Random rnd = new Random(); int succ = 0; for (int i = 0; i < num; i++) { if (runTest(rnd.nextInt(2) + 1)) { succ++; } } return (float) succ / (float) num; }
public static void generateUseDef(Vertex vertex[], int nsym, int nactive, Random r) { int i; int j; int sym; System.out.println("generating usedefs..."); for (i = 0; i < vertex.length; ++i) { for (j = 0; j < nactive; ++j) { sym = Math.abs(r.nextInt()) % nsym; if (j % 4 != 0) { if (!vertex[i].def.get(sym)) vertex[i].use.set(sym); } else { if (!vertex[i].use.get(sym)) vertex[i].def.set(sym); } } } }
/** Randomly permutes the specified list using a default source of randomness. */ public static void shuffle(List<?> list) { int size = list.size(); for (int i = size; i > 1; i--) { swap(list, i - 1, r.nextInt(i)); } }
public static void spawn(PcInstance pc, int npcId, int randomRange, int timeMillisToDelete) { try { NpcInstance npc = NpcTable.getInstance().newNpcInstance(npcId); npc.setId(IdFactory.getInstance().nextId()); npc.setMap(pc.getMapId()); if (randomRange == 0) { npc.getLocation().set(pc.getLocation()); npc.getLocation().forward(pc.getHeading()); } else { int tryCount = 0; do { tryCount++; npc.setX(pc.getX() + Random.nextInt(randomRange) - Random.nextInt(randomRange)); npc.setY(pc.getY() + Random.nextInt(randomRange) - Random.nextInt(randomRange)); if (npc.getMap().isInMap(npc.getLocation()) && npc.getMap().isPassable(npc.getLocation())) { break; } Thread.sleep(1); } while (tryCount < 50); if (tryCount >= 50) { npc.getLocation().set(pc.getLocation()); npc.getLocation().forward(pc.getHeading()); } } npc.setHomeX(npc.getX()); npc.setHomeY(npc.getY()); npc.setHeading(pc.getHeading()); // 紀錄龍之門扉編號 if (npc.getNpcId() == 81273) { for (int i = 0; i < 6; i++) { if (!LsimulatorDragonSlayer.getInstance().getPortalNumber()[i]) { LsimulatorDragonSlayer.getInstance().setPortalNumber(i, true); // 重置副本 LsimulatorDragonSlayer.getInstance().resetDragonSlayer(i); npc.setPortalNumber(i); LsimulatorDragonSlayer.getInstance().portalPack()[i] = npc; break; } } } else if (npc.getNpcId() == 81274) { for (int i = 6; i < 12; i++) { if (!LsimulatorDragonSlayer.getInstance().getPortalNumber()[i]) { LsimulatorDragonSlayer.getInstance().setPortalNumber(i, true); // 重置副本 LsimulatorDragonSlayer.getInstance().resetDragonSlayer(i); npc.setPortalNumber(i); LsimulatorDragonSlayer.getInstance().portalPack()[i] = npc; break; } } } LsimulatorWorld.getInstance().storeObject(npc); LsimulatorWorld.getInstance().addVisibleObject(npc); if (npc.getTempCharGfx() == 7548 || npc.getTempCharGfx() == 7550 || npc.getTempCharGfx() == 7552 || npc.getTempCharGfx() == 7554 || npc.getTempCharGfx() == 7585 || npc.getTempCharGfx() == 7591) { npc.broadcastPacket(new S_NPCPack(npc)); npc.broadcastPacket(new S_DoActionGFX(npc.getId(), ActionCodes.ACTION_AxeWalk)); } else if (npc.getTempCharGfx() == 7539 || npc.getTempCharGfx() == 7557 || npc.getTempCharGfx() == 7558 || npc.getTempCharGfx() == 7864 || npc.getTempCharGfx() == 7869 || npc.getTempCharGfx() == 7870) { for (PcInstance _pc : LsimulatorWorld.getInstance().getVisiblePlayer(npc, 50)) { if (npc.getTempCharGfx() == 7539) { _pc.sendPackets(new S_ServerMessage(1570)); } else if (npc.getTempCharGfx() == 7864) { _pc.sendPackets(new S_ServerMessage(1657)); } npc.onPerceive(_pc); S_DoActionGFX gfx = new S_DoActionGFX(npc.getId(), ActionCodes.ACTION_AxeWalk); _pc.sendPackets(gfx); } npc.npcSleepTime(ActionCodes.ACTION_AxeWalk, NpcInstance.ATTACK_SPEED); } else if (npc.getTempCharGfx() == 145) { // 史巴托 npc.setStatus(11); npc.broadcastPacket(new S_NPCPack(npc)); npc.broadcastPacket(new S_DoActionGFX(npc.getId(), ActionCodes.ACTION_Appear)); npc.setStatus(0); npc.broadcastPacket(new S_CharVisualUpdate(npc, npc.getStatus())); } npc.turnOnOffLight(); npc.startChat(NpcInstance.CHAT_TIMING_APPEARANCE); // チャット開始 if (0 < timeMillisToDelete) { LsimulatorNpcDeleteTimer timer = new LsimulatorNpcDeleteTimer(npc, timeMillisToDelete); timer.begin(); } } catch (Exception e) { _log.log(Level.SEVERE, e.getLocalizedMessage(), e); } }
/** @天气 0<无雪雨> 1<小雪>、2<中雪> 3<大雪> 16<停止下雨> 17<小雨> 18<中雨> 19<大雨> */ public Weather() { final int ran = Random.nextInt(8); // 读取乱数 L1World.getInstance().setWeather(WeatherId[ran]); L1World.getInstance().broadcastPacketToAll(new S_Weather(WeatherId[ran])); }
/** * Randomly rearrange an array. The random numbers used depend on the time and day. * * @param a the array. */ public static final <AnyType> void permute(AnyType[] a) { Random r = new Random(); for (int j = 1; j < a.length; j++) swapReferences(a, j, r.nextInt(0, j)); }
/** * Sleeps for a random number of milliseconds. * * @param min the minimum sleep time. * @param max the maximum sleep time. */ public static void sleep(final int min, final int max) { sleep(Random.nextInt(min, max)); }