Exemplo n.º 1
0
  public StarField(final int aNumberOfStars, final CharGenerator aStarsGenerator) {
    final int intensitySteps = aStarsGenerator.charsPerRow * aStarsGenerator.charsPerColumn;
    // #if DEBUG
    Assert.isTrue("stars generator should have at least one frame", intensitySteps > 0);
    // #endif

    myStars = new CharData[intensitySteps];
    for (int idx = 0; idx < myStars.length; idx++) {
      myStars[idx] = aStarsGenerator.getCharData(idx);
    }

    myNumberOfStars = aNumberOfStars;
    myStarsX = new float[myNumberOfStars];
    myStarsY = new float[myNumberOfStars];
    myStarsZ = new float[myNumberOfStars];

    final Random random = new Random();
    for (int idx = 0; idx < myNumberOfStars; idx++) {
      myStarsX[idx] = random.nextFloat(UNIVERSE_HALF);
      myStarsY[idx] = random.nextFloat(UNIVERSE_HALF);
      myStarsZ[idx] = random.nextFloat(UNIVERSE_HALF);
    }

    setAnimatedAxes(true, true, true);
  }
Exemplo n.º 2
0
 // 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
 }
Exemplo n.º 3
0
 public static void extra(Player player, int[] possibilities, boolean tavern) {
   if (possibilities.length > 0) {
     int extra = Random.integer_of(possibilities);
     if (player.water + extra > player.water_max) {
       extra = player.water_max - player.water;
       if (extra == 0)
         Type.delay_line(
             "💧: "
                 + Random.text_of(
                     new String[] {
                       "Your waterskin is already full of water, so you add no more.",
                       "There is no room in your waterskin to carry any more water."
                     }));
     } else if (extra == 0 && !tavern)
       Type.delay_line("💧: " + Random.text_of(new String[] {"You acquire no extra water."}));
     player.water += extra;
     if (extra > 0)
       Type.delay_line(
           "💧: "
               + Random.text_of(
                   new String[] {
                     "You fill up your waterskin, increasing your amount of water by "
                         + extra
                         + " to now be "
                         + player.water,
                     "You add " + extra + " water to your waterskin"
                   })
               + ".");
   }
 }
 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();
 }
Exemplo n.º 5
0
  private static void gas(double chance) {
    if (Random.whole() <= chance) {
      Wait.milliseconds(322);
      System.out.print("\n\n");

      Burp burp = new Burp();
      if (Random.whole() <= .12) gas(1);
    }
  }
Exemplo n.º 6
0
  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;
  }
Exemplo n.º 7
0
 private static void drink(
     Player player,
     int amount_min,
     int amount_max,
     int[] extra_possibilities,
     boolean tavern,
     double gas_chance) {
   int amount = Random.integer_from(amount_min, amount_max);
   for (int i = 0; i < amount; i++) {
     Type.delay(".", 1100);
   }
   System.out.println();
   boolean overdrinking_weaken = false;
   Type.delay("💧: ");
   if (player.wetness + amount < player.quenched)
     Type.delay_line(
         Random.text_of(
             new String[] {
               "You could drink some more.",
               "You are still thirsty.",
               "Your throat is still somewhat dry."
             }));
   else if (player.wetness + amount == player.quenched)
     Type.delay_line(
         Random.text_of(
             new String[] {
               "You have drunk enough.",
               "You have quenched your thirst.",
               "You are no longer thirsty."
             }));
   else {
     if (player.wetness == player.quenched) {
       Type.delay_line(
           Random.text_of(new String[] {"You have overdrunk.", "You feel waterlogged."}));
       overdrinking_weaken = true;
       if (gas_chance + .65 <= .9) gas_chance += .65;
       else gas_chance = .9;
     } else
       Type.delay_line(
           Random.text_of(
               new String[] {
                 "You have drunk enough.",
                 "You have quenched your thirst.",
                 "You are no longer thirsty."
               }));
     amount = player.quenched - player.wetness;
   }
   player.wetness += amount;
   player.display_wetnessbar();
   if (overdrinking_weaken) player.weaken(1);
   if (player.wetness >= player.quenched - 1) extra(player, extra_possibilities, tavern);
   gas(gas_chance);
 }
Exemplo n.º 8
0
  public static final double integrate(int Num_samples) {

    Random R = new Random(SEED);

    int under_curve = 0;
    for (int count = 0; count < Num_samples; count++) {
      double x = R.nextDouble();
      double y = R.nextDouble();

      if (x * x + y * y <= 1.0) under_curve++;
    }

    return ((double) under_curve / Num_samples) * 4.0;
  }
Exemplo n.º 9
0
  public void testRandom() {
    for (int i = 0; i < 100; i++) {

      int randomValue = Random.random(0, 100);
      assertTrue("value should be greater equals to 0", randomValue >= 0);
      assertTrue("value should be less equals to 100", randomValue <= 100);

      randomValue = Random.random(0, 1);
      assertTrue("value should be either 0 or 1", randomValue == 0 || randomValue == 1);

      randomValue = Random.random(6, 7);
      assertTrue("value should be either 6 or 7", randomValue == 6 || randomValue == 7);
    }
  }
Exemplo n.º 10
0
  @Override
  void generate_internal(Random generator, Palette palette) {
    speed = generator.getUniform(2.0f, 32.0f);
    terminal_speed = generator.getUniform(.1f, 3.0f);
    dspeeddt = generator.getUniform(0.0001f, 0.001f);

    theta = generator.getUniform(-(float) Math.PI, (float) Math.PI);
    dthetadt = 0.0f;
    d2thetadt2 = generator.getTwoRanges(0.001f, 0.01f);

    colour = palette.get_muon_pair(generator);
    colour.positive |= 0x4a000000;
    colour.negative |= 0x4a000000;
  }
Exemplo n.º 11
0
  public void testRandomNegative() {
    for (int i = 0; i < 100; i++) {

      int randomValue = Random.random(-100, 0);
      assertTrue(randomValue <= 0);
      assertTrue(randomValue >= -100);

      randomValue = Random.random(-4, 10);
      assertTrue(randomValue <= 10);
      assertTrue(randomValue >= -4);

      randomValue = Random.random(-4, -3);
      assertTrue(randomValue == -3 || randomValue == -4);
    }
  }
Exemplo n.º 12
0
  /* =============================================================================
   * initializeManager
   * =============================================================================
   */
  public Manager initializeManager() {
    int i;
    int t;
    System.out.println("Initializing manager... ");

    Random randomPtr = new Random();
    randomPtr.random_alloc();
    Manager managerPtr = new Manager();

    int numRelation = RELATIONS;
    int ids[] = new int[numRelation];
    for (i = 0; i < numRelation; i++) {
      ids[i] = i + 1;
    }

    for (t = 0; t < 4; t++) {

      /* Shuffle ids */
      for (i = 0; i < numRelation; i++) {
        int x = randomPtr.posrandom_generate() % numRelation;
        int y = randomPtr.posrandom_generate() % numRelation;
        int tmp = ids[x];
        ids[x] = ids[y];
        ids[y] = tmp;
      }

      /* Populate table */
      for (i = 0; i < numRelation; i++) {
        boolean status;
        int id = ids[i];
        int num = ((randomPtr.posrandom_generate() % 5) + 1) * 100;
        int price = ((randomPtr.posrandom_generate() % 5) * 10) + 50;
        if (t == 0) {
          status = managerPtr.manager_addCar(id, num, price);
        } else if (t == 1) {
          status = managerPtr.manager_addFlight(id, num, price);
        } else if (t == 2) {
          status = managerPtr.manager_addRoom(id, num, price);
        } else if (t == 3) {
          status = managerPtr.manager_addCustomer(id);
        }
        // assert(status);
      }
    } /* for t */

    System.out.println("done.");
    return managerPtr;
  }
Exemplo n.º 13
0
 public void testRandomInputOrder() {
   for (int i = 0; i < 100; i++) {
     int randomValue = Random.random(100, -200);
     assertTrue("value should be greater equals to -200", randomValue >= -200);
     assertTrue("value should be less equals to 100", randomValue <= 100);
   }
 }
Exemplo n.º 14
0
 public void event(Player player) {
   spectacle();
   if (player.health > 8 && Random.whole() <= .767) {
     System.out.println();
     Type.delay_line(
         Random.text_of(
             new String[] {
               "You bump into a spike!",
               "You are standing in a pool of acid!",
               "Flames shoot out of a wall, singeing you!",
               "A poison dart shoots out of a wall, burying into you!",
               "You get zapped as you step onto a metal grate!"
             }));
     player.trap_weaken(Random.integer_from(5, 8));
   }
 }
Exemplo n.º 15
0
 public Pause() {
   if (Act.input_backup.contains("pause") && Random.binary()) {
     Halt halt = new Halt();
   } else {
     Type.delay(
         Random.text_of(
             new String[] {
               "You pause for a moment.",
               "You pause for a moment, absorbing the view.",
               "You pause to admire your surroundings.",
               "You take a moment to admire your surroundings."
             }));
     for (int i = 0; i < Random.integer_from(1, 4); i++) Type.delay(".", 750);
     System.out.println();
   }
 }
Exemplo n.º 16
0
 /**
  * @param minumum
  * @param maximum
  */
 public static void sleep(final int minumum, final int maximum) {
   try {
     Thread.sleep(Random.between(minumum, maximum));
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
 }
Exemplo n.º 17
0
  public Underdark_Cavern() {
    super();

    context =
        Random.text_of(new String[] {"inside", "within"})
            + " a "
            + Random.text_of(new String[] {"cavern of the Underdark", "dark cavern underground"})
            + ".";
    description =
        Random.text_of(
            new String[] {"The air is stale.", "You notice water trickling next to your feet."});
    large_character_placements =
        new String[] {
          "aside the rock wall",
          "aside the stone wall",
          "aside the stippled wall",
          "on a curved shale table",
          "under some stalactites",
          "between some stalagmites",
          "next to some glowing mushrooms on the wall",
          "next to an ore vein",
          "among a pile of bones",
          "in the hole to another passage",
          "closer to the entrance",
          "in the depth of the cavern",
          "near the back",
          "at the opening to the cavern",
          "on the edge of an acid lake",
          "by a pool of acid"
        };
    noncharacter_placements =
        new String[] {
          "on the rock floor",
          "on the stone floor",
          "on the stippled ground",
          "in a puddle of stagnant water",
          "over a tiny stream of water going through the cracks of the cavern",
          "in some sticky goo"
        };
    moba =
        Array.combine(
            moba_underground_with_gremlin, mobs_permute(new String[] {"Grell", "Otyugh"}));
    if (Random.whole() <= moba_elemental_chance)
      moba =
          Array.combine(
              moba, mobs_permute(new String[] {"Earth_Elemental", "Galeb_Duhr", "Gargoyle"}));
  }
Exemplo n.º 18
0
  /* =============================================================================
   * initializeClients
   * =============================================================================
   */
  public Client[] initializeClients(Manager managerPtr) {
    Random randomPtr;
    Client clients[];
    int i;
    int numClient = CLIENTS;
    int numTransaction = TRANSACTIONS;
    int numTransactionPerClient;
    int numQueryPerTransaction = NUMBER;
    int numRelation = RELATIONS;
    int percentQuery = QUERIES;
    int queryRange;
    int percentUser = USER;

    System.out.println("Initializing clients... ");

    randomPtr = new Random();
    randomPtr.random_alloc();

    clients = new Client[numClient];

    numTransactionPerClient = (int) ((double) numTransaction / (double) numClient + 0.5);
    queryRange = (int) ((double) percentQuery / 100.0 * (double) numRelation + 0.5);

    for (i = 0; i < numClient; i++) {
      clients[i] =
          new Client(
              i,
              managerPtr,
              numTransactionPerClient,
              numQueryPerTransaction,
              queryRange,
              percentUser);
    }

    System.out.println("done.");
    System.out.println("    Transactions        = " + numTransaction);
    System.out.println("    Clients             = " + numClient);
    System.out.println("    Transactions/client = " + numTransactionPerClient);
    System.out.println("    Queries/transaction = " + numQueryPerTransaction);
    System.out.println("    Relations           = " + numRelation);
    System.out.println("    Query percent       = " + percentQuery);
    System.out.println("    Query range         = " + queryRange);
    System.out.println("    Percent user        = " + percentUser);

    return clients;
  }
Exemplo n.º 19
0
  @Override
  public void doWork() throws OperatorException {

    ExampleSet exampleSet = exampleSetInput.getData();

    IPosOnlyFeedback training_data = new PosOnlyFeedback();
    IEntityMapping user_mapping = new EntityMapping();
    IEntityMapping item_mapping = new EntityMapping();

    if (exampleSet.getAttributes().getSpecial("user identification") == null) {
      throw new UserError(this, 105);
    }

    if (exampleSet.getAttributes().getSpecial("item identification") == null) {
      throw new UserError(this, 105);
    }

    Attributes Att = exampleSet.getAttributes();
    AttributeRole ur = Att.getRole("user identification");
    Attribute u = ur.getAttribute();
    AttributeRole ir = Att.getRole("item identification");
    Attribute i = ir.getAttribute();

    for (Example example : exampleSet) {

      double j = example.getValue(u);
      int uid = (int) j;

      j = example.getValue(i);
      int iid = (int) j;

      training_data.Add(user_mapping.ToInternalID(uid), item_mapping.ToInternalID(iid));
      checkForStop();
    }

    System.out.println(training_data.GetMaxItemID() + " " + training_data.GetMaxUserID());

    Random recommendAlg = new Random();
    recommendAlg.SetFeedback(training_data);
    recommendAlg.user_mapping = user_mapping;
    recommendAlg.item_mapping = item_mapping;
    recommendAlg.Train();

    exampleSetOutput.deliver(exampleSet);
    exampleSetOutput1.deliver(recommendAlg);
  }
Exemplo n.º 20
0
  public static void main(String[] args) {
    final int MIN = 1;
    final int MAX = 100;

    int guess;
    int randomInt;

    Random random = new Random(MIN, MAX);
    randomInt = random.getValue();

    Interaction.summarizeProgram();

    do {
      Interaction.requestInput();
      guess = Interaction.getInput();
    } while (!Interaction.giveHintIfWrong(guess, randomInt));
  }
Exemplo n.º 21
0
 @Override
 public void run() {
   for (Random r : RandomScripts) {
     if (r.startCondition()) {
       r.onStart();
       while (!r.isDone) {
         int s = r.loop();
         try {
           Thread.sleep(s);
         } catch (InterruptedException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
         }
       }
     }
   }
 }
Exemplo n.º 22
0
  public Mountain_Range() {
    super();

    context = "in a mountain range.";
    description =
        Random.text_of(
            new String[] {
              "The other peaks you can see from this vantage point are snowy.",
              "A horde of goblins is marching out of a hole in a nearby mountain.",
              "A large bird is soaring from this mountain away to another.",
              "A giant is trudging down a steep path below you."
            });
    large_character_placements =
        new String[] {
          "halfway up a mountain, along a narrow rocky walkway",
          "next to some of the many boulders where the two nearest mountains meet",
          "just outside of a hole in the mountain",
          "near a steep peak",
          "on a narrow incline",
          "on a rocky ledge off of the mountain",
          "by the trees of the foothills",
          "at the top of a slope in the foothills",
          "among the debris of a settled avalanche",
          "in the crag between two broken rock faces",
          "inside a tunnel going through near the mountaintop",
          "against a sheer rock wall"
        };
    noncharacter_placements =
        new String[] {"among the grass and scattered rocks of the mountainside"};
    moba =
        Array.combine(
            moba_gremlin,
            mobs_permute(
                new String[] {"Hill_Giant", "Hill_Giant", "Hill_Giant", "Manticore", "Roc"}));
    if (Random.whole() <= moba_roamers_chance) moba = Array.combine(moba, moba_roamers);
    if (Random.whole() <= moba_elemental_chance)
      moba =
          Array.combine(
              moba, mobs_permute(new String[] {"Earth_Elemental", "Galeb_Duhr", "Gargoyle"}));
    if (Random.whole() <= moba_giant_chance)
      moba =
          Array.combine(
              moba,
              mobs_permute(new String[] {"Fire_Giant", "Frost_Giant", "Stone_Giant", "Yeti"}));
  }
 protected void eliminateAnswer() {
   while (true) {
     int guess = Random.getRandomTo(answers.size());
     if (!unremovables.contains(answers.get(guess))) {
       answers.remove(guess);
       return;
     }
   }
 }
Exemplo n.º 24
0
  public Arena() {
    super();

    context = "in the arena!";
    description =
        Random.text_of(
            new String[] {
              "You stand on worn and bloody sands, surrounded by traps, death machinery, monsters, and gladiators. Bodies lie here and there. Other combatants fight to the death. Crowded stands encircling the colosseum seat uncountable people, cheering on the madness from relative safety."
            });
    large_character_placements =
        new String[] {
          "in a pool of blood",
          "on the dusty and stamped ground",
          "adjacent to a spiky protrusion from an arena block",
          "on a tile away from most other contended zones",
          "against the wall of the stands",
          "on the metal grate trapdoor",
          "on a circular metal grate"
        };
    noncharacter_placements =
        new String[] {
          "among the debris of a tile ground up by action",
          "on the scarred arena surface",
          "on the floor of the main dueling dais"
        };
    moba =
        Array.combine(
            moba_fighters,
            moba_fighters,
            moba_fighters,
            moba_fighters,
            moba_fighters,
            moba_fighters,
            moba_fighters,
            moba_fighters,
            moba_fighters,
            moba_fighters,
            moba_gremlin,
            mobs_permute(
                new String[] {
                  "Gorgon",
                  "Helmed_Horror",
                  "Gorgon",
                  "Helmed_Horror",
                  "Gorgon",
                  "Helmed_Horror",
                  "Gorgon",
                  "Helmed_Horror",
                  "Gorgon",
                  "Helmed_Horror",
                  "Gorgon",
                  "Helmed_Horror",
                  "Gorgon",
                  "Helmed_Horror"
                }));
  }
Exemplo n.º 25
0
  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]);
      }
    }
  }
Exemplo n.º 26
0
 private String article_species_for_random_combatant_from_moba() {
   String combatant = Text.lower(Random.text_of(moba));
   combatant = combatant.substring(combatant.indexOf(".") + 1);
   for (int i = 0; i < combatant.length(); i++) {
     if (combatant.charAt(i) == '_')
       combatant = combatant.substring(0, i) + " " + combatant.substring(i + 1);
   }
   if (Text.vowel(combatant)) return "an " + combatant;
   else return "a " + combatant;
 }
Exemplo n.º 27
0
    public TextString next() {
      TextString str = null;
      if (numberOfWordsToGenerate > 0) {
        byte length;

        do {
          byte n = rand.getNonNegativeByte();
          length = (byte) (n % 10);
        } while (length == 0);

        str = new TextString(length);
        while (length > 0) {
          byte ascii = (byte) ((rand.getByte() % 28) + 'A');
          str.add((char) ascii);
          length--;
        }
        numberOfWordsToGenerate--;
      }
      return str;
    }
Exemplo n.º 28
0
 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);
 }
Exemplo n.º 29
0
 public void event(Player player) {
   spectacle();
   if (player.health < player.healthy) {
     Type.delay("You find respite here.");
     int amount = Random.integer_from(1, 4);
     for (int i = 0; i < amount; i++) {
       Type.delay(".", 1250);
     }
     System.out.println();
     player.recover(1 + amount);
   }
 }
Exemplo n.º 30
0
 @Deprecated
 @operator(value = "rnd_float")
 @doc(
     deprecated = "Use rnd instead with a float argument",
     examples = {
       @example(
           value = "rnd_float(3)",
           equals = "a random float between 0.0 and 3.0",
           test = false)
     },
     see = {"rnd"})
 public static Double opRndFloat(final IScope scope, final Double max) {
   return Random.opRnd(scope, max);
 }