Refine search
public ConcatVectorConstructionRecord(Random r, int[] sizes) { int length = sizes.length; componentSizes = sizes; densePieces = new double[length][]; sparseOffsets = new int[length]; sparseValues = new double[length]; for (int i = 0; i < length; i++) { boolean sparse = componentSizes[i] == -1; if (sparse) { sparseOffsets[i] = r.nextInt(100); sparseValues[i] = r.nextFloat(); } else { densePieces[i] = new double[componentSizes[i]]; for (int j = 0; j < densePieces[i].length; j++) { densePieces[i][j] = r.nextFloat(); } } } }
@Override public void init() { final Random rand = new Random(System.currentTimeMillis()); final int start = rand.nextInt(cardinality); final int end = start + cardinality; for (int i = start; i < end; i++) { case LONG: longValues = new ArrayList<Long>(); final long longStart = rand.nextInt(cardinality); final long longEnd = longStart + cardinality; for (long i = longStart; i < longEnd; i++) { case FLOAT: floatValues = new ArrayList<Float>(); final float floatStart = rand.nextFloat() * rand.nextInt(1000); int floatCounter = 1; while (true) {
@Override protected TestUserClassBase[] getTestData() { Random rnd = new Random(874597969123412341L); return new TestUserClassBase[]{ new TestUserClass1(rnd.nextInt(), "foo", rnd.nextLong()), new TestUserClass2(rnd.nextInt(), "bar", rnd.nextFloat()), new TestUserClass3(rnd.nextInt(), "bar", rnd.nextFloat()) }; }
/** * From a list of regions pick a random one. Null can be returned which * {@link StochasticLoadBalancer#balanceCluster(Map)} recognize as signal to try a region move * rather than swap. * * @param cluster The state of the cluster * @param server index of the server * @param chanceOfNoSwap Chance that this will decide to try a move rather * than a swap. * @return a random {@link RegionInfo} or null if an asymmetrical move is * suggested. */ protected int pickRandomRegion(Cluster cluster, int server, double chanceOfNoSwap) { // Check to see if this is just a move. if (cluster.regionsPerServer[server].length == 0 || RANDOM.nextFloat() < chanceOfNoSwap) { // signal a move only. return -1; } int rand = RANDOM.nextInt(cluster.regionsPerServer[server].length); return cluster.regionsPerServer[server][rand]; } protected int pickRandomServer(Cluster cluster) {
private static int calculateRandomizedModifier(Random random, ItemStack itemStack, int cost) { int modifier = calculateModifier(itemStack); if (modifier <= 0) { return -1; } modifier /= 4; modifier += 1; modifier = random.nextInt(modifier) + random.nextInt(modifier); modifier += 1 + cost; float randomValue = 1 + (random.nextFloat() + random.nextFloat() - 1.0F) * 0.15F; modifier = Math.round(modifier * randomValue); modifier = Math.max(1, modifier); return modifier; }
public static Vector3f[] getPositions(int count, long seed) { Random rnd = new Random(seed); Vector3f[] vectors = new Vector3f[count]; for (int i = 0; i < count; i++) { vectors[i] = new Vector3f((rnd.nextFloat() - 0.5f) * poiRadius, (rnd.nextFloat() - 0.5f) * poiRadius, (rnd.nextFloat() - 0.5f) * poiRadius); } return vectors; }
/** * @param loanRequest the loan request * @return a LoanQuote for the given request */ public LoanQuote quote(LoanRequest loanRequest) { Calendar calendar = Calendar.getInstance(); LoanQuote loanQuote = new LoanQuote(); Random random = new Random(); loanQuote.setQuoteDate(calendar.getTime()); calendar.add(Calendar.DAY_OF_YEAR, random.nextInt(25)); loanQuote.setExpirationDate(calendar.getTime()); loanQuote.setRate(random.nextFloat() + this.baseRate); loanQuote.setTerm(10 + random.nextInt(10)); loanQuote.setAmount(250000 + random.nextInt(40000)); loanQuote.setLender(this.name); return loanQuote; }
private void initWaterDropHolders(RectF bottleRect, RectF waterRect) { float bottleRadius = bottleRect.width() / 2.0f; float lowestWaterPointY = waterRect.top; float twoSidesInterval = 0.2f * bottleRect.width(); float atLeastDelayDuration = 0.1f; float unitDuration = 0.1f; float delayDurationRange = 0.6f; int radiusRandomRange = MAX_WATER_DROP_RADIUS - MIN_WATER_DROP_RADIUS; float currentXRandomRange = bottleRect.width() * 0.6f; for (int i = 0; i < DEFAULT_WATER_DROP_COUNT; i++) { WaterDropHolder waterDropHolder = new WaterDropHolder(); waterDropHolder.mRadius = MIN_WATER_DROP_RADIUS + mRandom.nextInt(radiusRandomRange); waterDropHolder.mInitX = bottleRect.left + twoSidesInterval + mRandom.nextFloat() * currentXRandomRange; waterDropHolder.mInitY = lowestWaterPointY + waterDropHolder.mRadius / 2.0f; waterDropHolder.mRiseHeight = getMaxRiseHeight(bottleRadius, waterDropHolder.mRadius, waterDropHolder.mInitX - bottleRect.left) * (0.2f + 0.8f * mRandom.nextFloat()); waterDropHolder.mDelayDuration = atLeastDelayDuration + mRandom.nextFloat() * delayDurationRange; waterDropHolder.mDuration = waterDropHolder.mRiseHeight / bottleRadius * unitDuration; mWaterDropHolders.add(waterDropHolder); } }
private List<GenericRow> createTestDataWithTimespec(TimeFieldSpec timeFieldSpec) { List<GenericRow> rows = new ArrayList<>(); Random random = new Random(); Map<String, Object> fields; for (int i = 0; i < NUM_ROWS; i++) { fields = new HashMap<>(); fields.put(D1, RandomStringUtils.randomAlphabetic(2)); fields.put(D2, RandomStringUtils.randomAlphabetic(5)); fields.put(M1, Math.abs(random.nextInt())); fields.put(M2, Math.abs(random.nextFloat())); long timestamp = System.currentTimeMillis(); Object timeColumnValue = timeFieldSpec.getIncomingGranularitySpec().fromMillis(timestamp); fields.put(timeFieldSpec.getName(), timeColumnValue); GenericRow row = new GenericRow(); row.init(fields); rows.add(row); } return rows; }
@Override protected void onUpdate() { final int digits = RANDOM.nextInt(2) + 6; ticker1.setText(getRandomNumber(digits)); final String currencyFloat = Float.toString(RANDOM.nextFloat() * 100); ticker2.setText("$" + currencyFloat.substring(0, Math.min(digits, currencyFloat.length()))); ticker3.setText(generateChars(RANDOM, alphabetlist, digits)); }
private void play() { Random random = new Random(); if (view.isReady()) { float maxScale = view.getMaxScale(); float minScale = view.getMinScale(); float scale = (random.nextFloat() * (maxScale - minScale)) + minScale; PointF center = new PointF(random.nextInt(view.getSWidth()), random.nextInt(view.getSHeight())); view.setPin(center); AnimationBuilder animationBuilder = view.animateScaleAndCenter(scale, center); if (getPage() == 3) { animationBuilder.withDuration(2000).withEasing(EASE_OUT_QUAD).withInterruptible(false).start(); } else { animationBuilder.withDuration(750).start(); } } }