Package Com.paic.pad.info.common.utils;import Java.util.hashmap;import Java.util.map;import java.util.Random; public class Getredpacket {public static map<string, string> Getrandomnum (double randomnum) {map<string, String > map = new hashmap<string, string> ();//7. A random number is generated, random random = new random (); Random number instance Double base = Random.nextdouble (); Produces a decimal point of less than 1 or greater than 0//8. The resulting random number is less than the number of winning probabilities, then the lottery fails if (Base > Randomnum) {String result = "Pips:" + base + "|< not winning >"; Map.put ("code", "0"); Map.put ( "Message", result);} else {String result = "pip:" + base + "winning"; Map.put ("Code", "1"); Map.put ("message", result);} return map;} public static void Main (string[] args) {int sumgift = 8000;//total prize int sumperson = 4000;//Total number of double randomnum = Sumperson * 1 .0/sumgift; The number of persons in addition to the prize gets the probability int count =0;for (int i = 0; i <; i++) {map<string, string> Map = Getrandomnum (randomnum); String code = map.get ("code"); String message = Map.get ("message"), if (Code.equals ("1")) {count + +;} System.out.prinTLN (message);} SYSTEM.OUT.PRINTLN ("Probability:" +randomnum + ", Total Jackpot:" + Count + "Times");}}
Java do probability