private String generateWorkingHours(final String locale) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, 8); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); long minHours = calendar.getTimeInMillis(); calendar.set(Calendar.HOUR_OF_DAY, 20); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); long maxHours = calendar.getTimeInMillis(); long workBeginHours = (long) (RANDOM.nextDouble() * (maxHours / 2 - minHours) + minHours); long workEndHours = (long) (RANDOM.nextDouble() * (maxHours - workBeginHours) + workBeginHours); Date workBeginDate = new Date(workBeginHours); Date workEndDate = new Date(workEndHours); StringBuilder workingHours = new StringBuilder(); SimpleDateFormat hourFormat = new SimpleDateFormat("HH:mm", LocaleUtils.toLocale(locale)); workingHours .append(hourFormat.format(workBeginDate)) .append("-") .append(hourFormat.format(workEndDate)); return workingHours.toString(); }
private void generateAndAddOperation() { Entity operation = dataDefinitionService.get(TECHNOLOGIES_PLUGIN, L_TECHNOLOGY_MODEL_OPERATION).create(); String number = generateString(CHARS_ONLY, RANDOM.nextInt(40) + 5); operation.setField(L_NUMBER, number); operation.setField("name", getNameFromNumberAndPrefix("Operation-", number)); operation.setField(L_BASIC_MODEL_STAFF, getRandomStaff()); operation.setField(L_BASIC_MODEL_WORKSTATION_TYPE, getRandomMachine()); operation.setField(L_TPZ, RANDOM.nextInt(1000)); operation.setField(L_TJ, RANDOM.nextInt(1000)); operation.setField("productionInOneCycle", RANDOM.nextInt(20)); operation.setField(L_NEXT_OPERATION_AFTER_PRODUCED_TYPE, RANDOM.nextInt(10)); operation.setField( "machineUtilization", numberService.setScale(new BigDecimal(RANDOM.nextDouble()).abs())); operation.setField( "laborUtilization", numberService.setScale(new BigDecimal(RANDOM.nextDouble()).abs())); operation.setField("nextOperationAfterProducedQuantity", RANDOM.nextInt(15)); operation.setField(L_NEXT_OPERATION_AFTER_PRODUCED_TYPE, "01all"); operation.setField("timeNextOperation", RANDOM.nextInt(30)); operation.setField("nextOperationAfterProducedQuantity", "0"); if (isEnabledOrEnabling("costNormsForOperation")) { operation.setField("pieceworkCost", RANDOM.nextInt(100)); operation.setField("machineHourlyCost", RANDOM.nextInt(100)); operation.setField("laborHourlyCost", RANDOM.nextInt(100)); operation.setField("numberOfOperations", RANDOM.nextInt(10) + 1); } dataDefinitionService.get(TECHNOLOGIES_PLUGIN, L_TECHNOLOGY_MODEL_OPERATION).save(operation); }
@Override public MultivariatePolyaDistribution createInstance() { final double r = 10.0; int N = 6; Vector a = VectorFactory.getDefault() .copyValues(r * RANDOM.nextDouble(), r * RANDOM.nextDouble(), r * RANDOM.nextDouble()); return new MultivariatePolyaDistribution(a, N); }
@Test // TODO if this interpolator cannot get the answer right then an exception should be thrown public void testFlat() { final double x1 = 10 * RANDOM.nextDouble(); final double x2 = 10 * RANDOM.nextDouble(); final double x3 = 10 * RANDOM.nextDouble(); // Fails utterly for flat surface since the variogram function will be zero for all r final InterpolatorND interpolator = new KrigingInterpolatorND(1.99); final InterpolatorNDDataBundle dataBundle = interpolator.getDataBundle(FLAT_DATA); assertEquals(INTERPOLATOR.interpolate(dataBundle, new double[] {x1, x2, x3}), 0, 0); }
@Override public void spawnServerSide( EntityPlayer player, NBTTagCompound dataFromClient, NBTTagCompound rewardData) { for (int i = 0; i < dataFromClient.getInteger(AMOUNTOFORBS_KEY); i++) { double X = player.posX, Y = player.posY, Z = player.posZ; X += (0.5 - RANDOM.nextDouble()); Z += (0.5 - RANDOM.nextDouble()); player.worldObj.spawnEntityInWorld( new EntityXPOrb(player.worldObj, X, Y, Z, RANDOM.nextInt(5) + 1)); } }
@Override public void testPDFKnownValues() { System.out.println("PDF.knownValues"); for (int i = 0; i < 100; i++) { UniformDistribution.PDF instance = this.createInstance().getProbabilityFunction(); double a = instance.getMinSupport(); double b = instance.getMaxSupport(); double x = (RANDOM.nextDouble() * (b - a + 2)) + a - 1; double h = 1 / (b - a); double y; if (x < a) { y = 0; } else if (x > b) { y = 0; } else { y = h; } double yhat = instance.evaluate(x); assertEquals(y, yhat); assertEquals(h, instance.evaluate(a)); assertEquals(h, instance.evaluate(b)); } }
@Test public void test() { for (int i = 0; i < 10; i++) { final double x = A + (B - A) * RANDOM.nextDouble(); final double y = 5 * NORMAL.nextRandom(); assertRoundTrip(RANGE_LIMITS, x); assertReverseRoundTrip(RANGE_LIMITS, y); assertGradient(RANGE_LIMITS, x); assertInverseGradient(RANGE_LIMITS, y); assertGradientRoundTrip(RANGE_LIMITS, x); } }
private void addSubstituteToProduct(final Entity product) { Entity substitute = dataDefinitionService.get(L_BASIC_PLUGIN_IDENTIFIER, "substitute").create(); String number = generateString(DIGITS_ONLY, RANDOM.nextInt(34) + 5); substitute.setField(L_NUMBER, number); substitute.setField(L_NAME, getNameFromNumberAndPrefix("ProductSubstitute-", number)); substitute.setField(L_BASIC_MODEL_PRODUCT, product); substitute.setField("priority", RANDOM.nextInt(7)); substitute = dataDefinitionService.get(L_BASIC_PLUGIN_IDENTIFIER, "substitute").save(substitute); addSubstituteComponent( substitute, getRandomProduct(), RANDOM.nextInt(997) * RANDOM.nextDouble()); }
@Override public void onNext(Word word) { Timber.d("Got word " + word + " and this is the subscriber " + this); if (RANDOM.nextDouble() <= 0.25 || currentAvailableWords.isEmpty()) { word = targetWord; } if (targetWordLanguage.equals(ENGLISH)) { view.showOptionalWord(word.getTextSpa()); currentDisplayedWord = word.getTextSpa(); } else { view.showOptionalWord(word.getTextEng()); currentDisplayedWord = word.getTextEng(); } }
@Override public void testCDFConstructors() { System.out.println("CDF Constructor"); UniformDistribution.CDF u = new UniformDistribution.CDF(); assertEquals(UniformDistribution.DEFAULT_MIN, u.getMinSupport()); assertEquals(UniformDistribution.DEFAULT_MAX, u.getMaxSupport()); double a = RANDOM.nextGaussian(); double b = RANDOM.nextDouble() + a; u = new UniformDistribution.CDF(a, b); assertEquals(a, u.getMinSupport()); assertEquals(b, u.getMaxSupport()); UniformDistribution.CDF u2 = new UniformDistribution.CDF(u); assertEquals(u.getMinSupport(), u2.getMinSupport()); assertEquals(u.getMaxSupport(), u2.getMaxSupport()); }
@Override protected DoubleMatrix1D getGlobalStart( final double forward, final double[] strikes, final double expiry, final double[] impliedVols) { final DoubleMatrix1D fitP = getPolynomialFit(forward, strikes, impliedVols); final double a = fitP.getEntry(0); final double b = fitP.getEntry(1); final double c = fitP.getEntry(2); double alpha, beta, rho, nu; // TODO make better use of the polynomial fit information if (_externalBeta) { beta = _beta; } else { beta = RANDOM.nextDouble(); } if (a <= 0.0) { // negative ATM vol - can get this if fit points are far from ATM double sum = 0; final int n = strikes.length; for (int i = 0; i < n; i++) { sum += impliedVols[i]; } final double approxAlpha = sum / n * Math.pow(forward, 1 - beta); alpha = (RANDOM.nextDouble() + 0.5) * approxAlpha; rho = RANDOM.nextDouble() - 0.5; nu = 0.5 * RANDOM.nextDouble() + 0.1; return new DoubleMatrix1D(alpha, beta, rho, nu); } if (Math.abs(b) < 1e-3 && Math.abs(c) < 1e-3) { // almost flat smile if (_externalBeta && _beta != 1.0) { s_logger.warn( "Smile almost flat. Cannot use beta = ", +_beta + " so extenal value ignored, and beta = 1.0 used"); } return new DoubleMatrix1D(a, 1.0, 0.0, Math.max(0.0, 4 * c)); } final double approxAlpha = a * Math.pow(forward, 1 - beta); alpha = (RANDOM.nextDouble() + 0.5) * approxAlpha; rho = RANDOM.nextDouble() - 0.5; nu = (RANDOM.nextDouble() + 0.5) * Math.max(0.0, 4 * c); return new DoubleMatrix1D(alpha, beta, rho, nu); }
@Override public UniformDistribution createInstance() { double a = RANDOM.nextGaussian(); double b = a + RANDOM.nextDouble() * 2.0; return new UniformDistribution(a, b); }