Changing probability in java -


this question has answer here:

i have been trying write program simple fighting simulator , task have ask user percentage of low, medium, , high attacks in fighting round.

so example, user inputs low = 50%, medium = 30%, , high = 20%. question stems here. how make in 1 round program print low 50% of time, medium 30% of time, , high 20% of time?

without giving exact java code, here need do:

  1. create set of intervals. in case, [0, 0.5>, [0.5, 0.8>; [0.8, 1.0>.
  2. generate random number between 0 , 1
  3. see interval falls in. fall first interval 50% of time, second interval 30% of time, , third interval 20% of time

you can figure out here?

afterthought: in case, values user inputs add 100%. in general may not true; compute "apparent intervals" first, , scale them maximum of 1. let's user entered 50,30,30% (can't math...). intervals be

0, .5 .5, .8 .8, 1.1 

and have divide 1.1 right intervals. or multiply random number 1.1.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -