List of usage examples for java.lang Math random
public static double random()
From source file:com.ideabase.repository.test.TestCaseRepositoryHelper.java
public static List<Integer> fixCreateItemsWithRandomName(final RepositoryService pRepositoryService, final int pNumberOfItems) { final List<Integer> itemIds = new ArrayList<Integer>(); final String dummyName = String.valueOf((System.currentTimeMillis() + Math.random())).replace(".", ""); final String dummyEmail = String.valueOf((System.currentTimeMillis() + Math.random()) + "@somewherein.net") .replace(".", ""); for (int i = 0; i < pNumberOfItems; i++) { final GenericItem item = new GenericItem(); item.addField("vendor", "test" + i); item.addField("name", i + dummyName); item.addField("email", i + dummyEmail); item.addField("currentTime", String.valueOf(System.currentTimeMillis())); item.setTitle(i + dummyName);//from w w w . j ava 2 s .com item.setCreatedOn(new Timestamp(System.currentTimeMillis())); item.setLastUpdatedOn(item.getCreatedOn()); itemIds.add(pRepositoryService.save(item)); } return itemIds; }
From source file:com.ciphertool.genetics.algorithms.crossover.ConservativeCentromereCrossoverAlgorithm.java
/** * This crossover algorithm finds all the points where both parent * Chromosomes can safely be split in half without splitting a Gene, and * then picks one of those at random as the centromere for crossover. * /* w w w .j ava2 s . c o m*/ * @see com.ciphertool.genetics.algorithms.crossover.zodiacengine.genetic.CrossoverAlgorithm#crossover(com.ciphertool.genetics.entities.zodiacengine.genetic.Chromosome, * com.ciphertool.genetics.entities.zodiacengine.genetic.Chromosome) */ @Override public List<Chromosome> crossover(Chromosome parentA, Chromosome parentB) { List<Integer> potentialCentromeres = findPotentialCentromeres(parentA, parentB); /* * Casting to int will truncate the number, giving us an index we can * safely use against lists. */ int centromere = potentialCentromeres.get((int) (Math.random() * potentialCentromeres.size())); List<Chromosome> children = new ArrayList<Chromosome>(); Chromosome firstChild = performCrossover(parentA, parentB, centromere); // The chromosome will be null if it's identical to one of its parents if (firstChild != null) { children.add(firstChild); parentA.increaseNumberOfChildren(); parentB.increaseNumberOfChildren(); } return children; }
From source file:blue.soundObject.jmask.Random.java
public double getValue(double time) { double range = max - min; return min + (range * Math.random()); }
From source file:classifiers.ComplexClassifierZufall.java
public ComplexClassifierZufall(Instances inst, int anzahl) { super(inst);//from w w w . j a v a 2 s . c om Datenbank = new Instances(super.getinst()); this.vernetzung = (int) (Math.random() * 101); Model = new GraphMitAngabeVernetzungsgrad(inst, vernetzung); Model.strukturiereGraph(); list = new ArrayList<>(); Classparam = new double[inst.numInstances()]; this.anzahldurchlauf = anzahl; trainergebnisse = new double[anzahldurchlauf][2]; testergebnisse = new double[anzahldurchlauf][2]; Modelergebnisse = new double[1][2]; validierungsergebnisse = new double[1][2]; struct = new BayesNetz(inst, Model); }
From source file:iqq.im.action.GetCaptchaImageAction.java
@Override protected QQHttpRequest onBuildRequest() throws QQException, JSONException { QQHttpRequest req = createHttpRequest("GET", QQConstants.URL_GET_CAPTCHA); req.addGetValue("aid", QQConstants.APPID); req.addGetValue("r", Math.random() + ""); req.addGetValue("uin", uin + ""); return req;/* w ww. java 2 s . c om*/ }
From source file:org.openbaton.nfvo.core.core.NetworkManagement.java
@Override public Network add(VimInstance vimInstance, Network network) throws VimException, PluginException { log.info("Creating network " + network.getName() + " on vim " + vimInstance.getName()); org.openbaton.nfvo.vim_interfaces.network_management.NetworkManagement vim; vim = vimBroker.getVim(vimInstance.getType()); //Define Network if values are null or empty if (network.getName() == null || network.getName().isEmpty()) network.setName(IdGenerator.createUUID()); if (network.getSubnets().isEmpty()) { //Define Subnet Subnet subnet = new Subnet(); subnet.setName(network.getName() + "_subnet"); subnet.setCidr("192.168." + (int) (Math.random() * 255) + ".0/24"); //Define list of Subnets for Network Set<Subnet> subnets = new HashSet<>(); subnets.add(subnet);//from w ww. j av a 2 s. c o m network.setSubnets(subnets); } //Create Network on cloud environment network = vim.add(vimInstance, network); //Create Network in NetworkRepository networkRepository.save(network); //Add network to VimInstance vimInstance.getNetworks().add(network); log.info("Created Network " + network.getName()); log.debug("Network details: " + network); return network; }
From source file:ar.com.zauber.commons.message.impl.mail.BalancerNotificationStrategy.java
/** @see NotificationStrategy#execute(NotificationAddress[], Message) */ @Override//from w ww.j a v a 2 s.c o m public final void execute(final NotificationAddress[] addresses, final Message message) { if (ratio == 0.0) { logger.debug("Sending using strategy2"); strategy2.execute(addresses, message); } else if (ratio == 1.0) { logger.debug("Sending using strategy1"); strategy1.execute(addresses, message); } else { if (Math.random() > ratio) { logger.debug("Sending using strategy2"); strategy2.execute(addresses, message); } else { logger.debug("Sending using strategy1"); strategy1.execute(addresses, message); } } }
From source file:org.jfree.chart.demo.CloneTest1.java
public void actionPerformed(ActionEvent actionevent) { if (actionevent.getActionCommand().equals("ADD_DATA")) { double d = 0.90000000000000002D + 0.20000000000000001D * Math.random(); lastValue = lastValue * d;//w w w. ja v a 2 s . c o m Millisecond millisecond = new Millisecond(); System.out.println("Now = " + millisecond.toString()); series.add(new Millisecond(), lastValue); } }
From source file:eu.ggnet.dwoss.rights.assist.gen.RightsGeneratorOperation.java
/** * Create the given amount of operators and personas and create a Addentional Operator with the Username "Adminuser" und clear text Password Test and All * Rights./*from w ww. j a v a 2 s .c o m*/ * <p> * .* @param countOfOperator * <p> * @param countOfOperator * @param countOfPersona */ public void make(int countOfOperator, int countOfPersona) { List<Persona> personas = new ArrayList<>(); for (int i = 0; i < countOfPersona; i++) { Persona persona = new Persona(); persona.setName("Persona " + i); persona.addAll(getRandomRights()); em.persist(persona); personas.add(persona); } for (int j = 0; j < countOfOperator; j++) { Operator operator = new Operator(); for (AtomicRight atomicRight : getRandomRights()) { operator.add(atomicRight); } operator.setUsername("User " + j); int till = (int) (Math.random() * countOfPersona - 1); for (Persona persona : personas.subList(0, till)) { operator.add(persona); } operator.setSalt(RandomStringUtils.randomAlphanumeric(6).getBytes()); operator.setPassword(AuthenticationBean .hashPassword(RandomStringUtils.randomAlphanumeric(15).toCharArray(), operator.getSalt())); operator.setQuickLoginKey((int) (Math.random() * 999)); em.persist(operator); } }
From source file:com.balero.models.TestDAO.java
@Transactional public void add() { Session session = sessionFactory.openSession(); Test test = new Test(); Double n = Math.random(); test.setName("user_" + n.toString()); test.setEmail("user@" + n.toString()); session.save(test);/*from w ww. j a v a 2 s . c om*/ session.flush(); session.close(); }