Example usage for java.lang Math random

List of usage examples for java.lang Math random

Introduction

In this page you can find the example usage for java.lang Math random.

Prototype

public static double random() 

Source Link

Document

Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0 .

Usage

From source file:com.strider.datadefender.extensions.BiographicFunctions.java

private static int randBetween(final int start, final int end) {
    return start + (int) Math.round(Math.random() * (end - start));
}

From source file:CookieBagV2.java

private void addRandomCookies() {
    int count = (int) (Math.random() * 10);
    int pick = (int) (Math.random() * 10);
    pick = pick > 6 ? 6 : pick;/*from w  ww. j  a v a 2 s .  c o  m*/
    if (count > 5)
        cookieBag.add(cookieJar[pick], count);
    else
        sortedCookieBag.add(cookieJar[pick], count);
}

From source file:Main.java

@Override
public void run() {
    try {//from  w w  w. j a va 2 s.  co m
        Thread.sleep(1000 + (int) (Math.random() * 3000));
        System.out.println(next());
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        latch.countDown();
    }
}

From source file:boutiqueEnLigne.service.GenerationNouveauCodePromoService.java

public void generate(int length, TypeCode tc, Double valeur) {
    String chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; // Tu supprimes les lettres dont tu ne veux pas
    String pass = "";
    for (int x = 0; x < length; x++) {
        int i = (int) Math.floor(Math.random() * 62); // Si tu supprimes des lettres tu diminues ce nb
        pass += chars.charAt(i);/* w w  w . j a  v  a 2s .co  m*/
    }
    System.out.println(pass);
    CodePromo cp = new CodePromo();
    cp.setCode(pass);
    cp.setTypecode(tc);
    cp.setValeur(valeur);
    codePromoService.save(cp);

}

From source file:com.apress.prospringintegration.corespring.aop.RandomPurchaseOrderGenerator.java

public PurchaseOrder getRandomOrder() {
    PurchaseOrder order = new PurchaseOrder();
    order.setItemCost((float) (Math.random() * 100.00));
    return order;
}

From source file:org.jongo.mocks.UserMock.java

public static UserMock getRandomInstance() {
    final UserMock instance = new UserMock();
    instance.name = new BigInteger(100, random).toString(32);
    instance.age = 1 + (int) (Math.random() * ((100 - 1) + 1));
    instance.birthday = dateFTR.parseDateTime(getRandomBirthDate());
    instance.lastupdate = new DateTime();
    instance.credit = new BigDecimal(random.nextDouble());
    return instance;
}

From source file:boutiqueEnLigne.service.GenerationCodeService.java

public String generateString(int length) {
    StringBuilder pass = new StringBuilder(charLength);

    boolean codeValide = false;

    do {//from   ww w  . jav  a 2  s.  c om
        for (int x = 0; x < length; x++) {
            int i = (int) (Math.random() * charLength);
            pass.append(chars.charAt(i));
        }

        Codepromo cp = codepromoService.findOneByCode(pass.toString());

        if (cp != null) {
            pass = new StringBuilder(charLength);
        }
        codeValide = true;

    } while (codeValide = false);

    return pass.toString();

}

From source file:com.sasav.blackjack.dao.GameDao.java

public Card pullRandomCardFromDeck(Game game, GameActor actor) {
    ArrayList<Card> cardDeck = game.getCardDeck();
    int index = (int) (Math.random() * cardDeck.size());
    Card card = cardDeck.get(index);//from  w  w w. ja  v  a2s.  c o m
    cardDeck.remove(index);
    Session session = sessionFactory.openSession();
    session.flush();
    session.close();
    return null;
}

From source file:com.marcosanta.service.impl.RecuperaServiceImpl.java

@Override
public String generaContrasena() {
    String contrasena = "";
    int longitud = base.length();
    for (int i = 0; i < 10; i++) {
        int numero = (int) (Math.random() * (longitud));
        String caracter = base.substring(numero, numero + 1);
        contrasena = contrasena + caracter;
    }/*from w  ww.java2 s . co m*/
    return contrasena;
}

From source file:io.spring.controller.EnrichmentController.java

@GetMapping("/enrich")
public String enrich() {
    if (Math.random() > .5) {
        throw new RuntimeException("I screwed up");
    } else {//w  w  w.  jav a  2 s .com
        this.count++;

        return String.format("Enriched %s", this.count);
    }
}