i'm creating plugin , i'm struggling figure out how pick winner based on percentage, using hashmap.
in plugin, each player deposits item, and, based on item's worth, receive percentage back. i'm trying pick winner based on probability. there multiple users depositing items, means number double.
is there way calculate this?
package com.test; import java.text.decimalformat; import java.util.collection; import java.util.hashmap; import java.util.iterator; import java.util.random; import java.util.set; public class main { static hashmap<string, double> jackpotentrys = new hashmap<string, double>(); static hashmap<string, double> jackpotpce = new hashmap<string, double>(); static hashmap<string, double> stage1jpe = new hashmap<string, double>(); public static void main(string[] args) { jackpotentrys.put("mrgreen33gamer", 155.000); jackpotentrys.put("xeneonhd", 270.000); jackpotentrys.put("badboybaldspot", 760.000); jackpotentrys.put("kingcreeper6", 455.000); jackpotentrys.put("kingcreeper5", 50.000); jackpotentrys.put("kingcreeper4", 100.000); jackpotentrys.put("kingcreeper3", 20.000); jackpotentrys.put("kingcreeper2", 15.000); jackpotentrys.put("kingcreeper1", 5.000); set<string> pces1 = jackpotentrys.keyset(); (iterator<string> = pces1.iterator(); i.hasnext(); ){ string key = (string) i.next(); double value = (double) jackpotentrys.get(key); } jpvalue(); pce_jpe_pick(); } public static void jpvalue(){ collection<double> values = jackpotentrys.values(); int total = 0; (double value : values) { total += value; } system.out.println("jackpot totalled at: " + total); } public static void pce_jpe_pick(){ system.out.println("========== new line =============="); set<string> pces1 = jackpotentrys.keyset(); (iterator<string> = pces1.iterator(); i.hasnext(); ){ string key = (string) i.next(); double value = (double) jackpotentrys.get(key); double finalpe = value / 1000; jackpotpce.put(key, finalpe); } set<string> pces2 = jackpotpce.keyset(); for(iterator<string> i2 = pces2.iterator(); i2.hasnext(); ){ string key = (string) i2.next(); double value = (double) jackpotpce.get(key); system.out.println(key + " has probability of double: " + value); } random r = new random(); double randomvalue = 0 + (1 - 0) * r.nextdouble(); system.out.println(randomvalue); } public static double probabilitycal(double playerdepot) { collection<double> values = jackpotentrys.values(); int total = 0; (double value : values) { total += value; } double percentage = (double) ((playerdepot * 100) / total); decimalformat df = new decimalformat("#.###"); double finalpercentage = double.parsedouble(df.format(percentage)); return finalpercentage; } } another thing: if trying pick winner had 33 percent each, how pick player?
if looking algorithm, can help. have 3 percentage values 25%, 25%, , 50%. have convert these consecutive ranges between 0 , 1 first becomes range 0 0.25, second becomes range 0.25 0.5, third becomes range 0.5 1. generate random double between 0 , 1 , whichever range random number falls in, winner.
Comments
Post a Comment