This is not just about finding a random number,  The answer I am looking for is how to add an expression to a random number to calculate a number based on the expression.   For example a base random number from a range of numbers,  + the current lvl of a character,  * the character's damage gain.  If I am creating a character that does damage between two numbers like this in java,   Damage = 44 to 55 per hit and I want to write this into a variable, how can I do this?  I am trying this,  double BottomDamage = 44 + level * 1.9; double TopDamage = 55 + level * 1.9;   What is the proper way to write something like this if the damage would be between these two numbers 44 through 55 + level * 1.9???
4701
How do I generate a random int value in a specific range? I have tried the following, but those do not work: Attempt 1: randomNum = minimum + (int)(Math.random() * maximum);  Bug: randomNum can be bigger than maximum. Attempt 2: Random rn = new Random(); int n = maximum - minimum + 1; int i = rn.nextInt() % n; randomNum =  minimum + i;  Bug: randomNum can be smaller than minimum.
101106
I am creating a Random Math Engine using the BGE and I am wondering how I can do mathematical operations between two properties. Example: "Property 1 + Property 2" and then it would output the answer in text when you hit "A". But I don't know how to add/subtract/multiply/divide properties together.
31874
All numbers that divide evenly into x.  I put in 4 it returns: 4, 2, 1  edit: I know it sounds homeworky.  I'm writing a little app to populate some product tables with semi random test data.  Two of the properties are ItemMaximum and Item Multiplier.  I need to make sure that the multiplier does not create an illogical situation where buying 1 more item would put the order over the maximum allowed.  Thus the factors will give a list of valid values for my test data.  edit++: This is what I went with after all the help from everyone.  Thanks again!  edit#: I wrote 3 different versions to see which I liked better and tested them against factoring small numbers and very large numbers.  I'll paste the results.  static IEnumerable&lt;int&gt; GetFactors2(int n) {     return from a in Enumerable.Range(1, n)                   where n % a == 0                   select a;                       }  private IEnumerable&lt;int&gt; GetFactors3(int x) {                 for (int factor = 1; factor * factor &lt;= x; factor++)     {         if (x % factor == 0)         {             yield return factor;             if (factor * factor != x)                 yield return x / factor;         }     } }  private IEnumerable&lt;int&gt; GetFactors1(int x) {     int max = (int)Math.Ceiling(Math.Sqrt(x));     for (int factor = 1; factor &lt; max; factor++)     {         if(x % factor == 0)         {             yield return factor;             if(factor != max)                 yield return x / factor;         }     } }   In ticks. When factoring the number 20, 5 times each:   GetFactors1-5,445,881 GetFactors2-4,308,234 GetFactors3-2,913,659       When factoring the number 20000, 5 times each:   GetFactors1-5,644,457 GetFactors2-12,117,938 GetFactors3-3,108,182
59865
I'm trying to make a game where the damage you deal is rolled by a dice. It all works. However, it keeps on giving the same values in a row so it isn't entirely random  ini_open("Health.ini"); attack = ini_read_real( "Attacks", "Felix", 0); ini_close(); global.damage=0 repeat(attack){ global.damage=irandom(6) }   if (global.damage ==0){instance_create_depth(300, 400, 0, obj_numbers0)} if (global.damage ==1){instance_create_depth(400, 400, 0, obj_numbers1)} if (global.damage ==2){instance_create_depth(500, 400, 0, obj_numbers2)} if (global.damage ==3){instance_create_depth(600, 400, 0, obj_numbers3)} if (global.damage ==4){instance_create_depth(700, 400, 0, obj_numbers4)} if (global.damage ==5){instance_create_depth(800, 400, 0, obj_numbers5)} if (global.damage ==6){instance_create_depth(900, 400, 0, obj_numbers6)}   The attack value is 1 because it is only one dice that is used for damage for now. The software I am using is Game Maker Studio 2
9683
Hey all I asked this over  =) and I got a good answer but I still have no idea whats going on. I want to know how the expression got to the answer and maybe the math behind how it was reasoned.. the steps if you would be so kind. The likelihood is I don't understand the equation.   I'm not a big maths person please be gentle :p     For all those playing along at home I'm reading Absolute Java 5th   Edition by Walter Savitch (Chapter 2 Page 66).      The Expression  double d = 12345.123456789; System.out.printf("START%12.5e END %n", d);       The Answer  START 1.23451e+04END       I understand the basic principles of this printf method's arguments   for example I know the '%' represents the start of the parameters.   '12' is the number of spacing, '.5' is the times the decimal point   will move.... I see the decimal point has moved 4 places towards the   left... can someone explain the principles of e-notation. Also how   this expression came to this answer =).      As far as e-notation go's its meant to be scientific notation;      So like 5.89e-4 would mean 0.000589 (move the decimal place if minus   left if not move the decimal place right).
61713
I'm struggling with coming up with an elegant solution to generating random events in the game that I'm working on.  Say there are 4 classes of events that can happen, with varying events in those classes that may occur.  So something along the lines of   main_events = {"common event", "not so common event", "somewhat rare event", "rare event"} sub_events[0] = {"common event 1", "common event 2",..} ...   I have a somewhat kludgey solution in place that first just has a random number generated between 0 and 100, and if the number falls within a given range then a main event will be triggered.  Then I'll do another random roll to see which sub event occurs.  Is there a better solution than something along these lines?  Like I mention, it doesn't feel very elegant, and I'd like to make it easily expandable for the addition of future events.
57093
I think there's a lot for me to learn about data types. Why this happens  double result = ((3/8)*100).ToString();   it gives zero .. should be 37,5 ... :(
99549
A red die, a blue die, and a yellow die (all six-sided) are rolled. We are interested in the probability that the number appearing on the blue die is less than that appearing on the yellow die which is less than that appearing on the red die $P(B &lt; Y &lt; R)$.  I know one way to calculate this is:  E = event that no two dice land on the same number:  $$P(E) = \frac{6 \cdot 5 \cdot 4}{6 \cdot 6 \cdot 6} = \frac{5}{9}$$  F = event that B &lt; Y &lt; R and no two dice land on the same number  $$P(F) = P(E) \cdot P(B &lt; Y &lt; R|E) = \frac{5}{9} \cdot \frac{1}{6} = \frac{5}{54}$$  Is there another way to find the number of outcomes where $B &lt; Y &lt; R$ using the formula $N(E)/N(S)$, where $N(S) = 6 \cdot 6 \cdot 6 = 216$?
470
On the , there is this line:      $p(\mathrm{height}|\mathrm{male}) = 1.5789$ (A probability distribution over 1 is OK. It is the area under the bell curve that is equal to 1.)    How can a value $&gt;1$ be OK? I thought all probability values were expressed in the range $0 \leq p \leq 1$. Furthermore, given that it is possible to have such a value, how is that value obtained in the example shown on the page?
7653
public class doublePrecision {     public static void main(String[] args) {          double total = 0;         total += 5.6;         total += 5.8;         System.out.println(total);     } }   The above code prints:  11.399999999999   How would I get this to just print (or be able to use it as) 11.4?
11107
Is there a function the .NET framework that can evaluate a numeric expression contained in a string and return the result? F.e.:  string mystring = "3*(2+4)"; int result = EvaluateExpression(mystring); Console.Writeln(result); // Outputs 18   Is there a standard framework function that you can replace my EvaluateExpression method with?
42365
OK so if your game rolls lots of dice you can just call a random number generator in a loop. But for any set of dice being rolled often enough you will get a distribution curve/histogram. So my question is there a nice simple calculation I can run that will give me a number that fits that distribution?  E.g. 2D6 - Score - % Probability  2 - 2.77%  3 - 5.55%  4 - 8.33%  5 - 11.11%  6 - 13.88%  7 - 16.66%  8 - 13.88%  9 - 11.11%  10 - 8.33%  11 - 5.55%  12 - 2.77%  So knowing the above you could roll a single d100 and work out an accurate 2D6 value. But once we start with 10D6, 50D6, 100D6, 1000D6 this could save a lot of processing time. So there must be a tutorial / method / algorithm that can do this fast? It is probably handy for stock markets, casinos, strategy games, dwarf fortress etc. What if you could simulate the outcomes of complete strategic battle that would take hours to play with a few calls to this function and some basic maths?
99975
How do I get a random  instance? It appears that the random module only returns floats which are a pita to convert to Decimals.
28516
How do I format a number in Java? What are the &quot;Best Practices&quot;? Will I need to round a number before I format it?  32.302342342342343 =&gt; 32.30 .7323 =&gt; 0.73  etc.
53171
Formatting numbers on a VF page, but I do a bunch of processing the Apex Class, so I would rather return the formatted String value from the controller.   I am doing something like this, but I just want the second number to appear as "(1500)" rather "-1500"  Getting lost in the Message Format docs, so hoping someone can guide me in the right direction...  List&lt;String&gt; args = new String[]{'0','number','###,###,###'}; system.debug('Positive' + String.format(  ( (1000) - (500.50)  ).round().format(), args) ); system.debug('Negative' + String.format(  ( (-1000) - (500.50)  ).round().format(), args) );
107627
Is it the same convention as those used in known programming languages such as Java and C? I'm trying to create a lot of variables and I want it to start with a number, but I'm not sure if it's okay.
35871
How does Python evaluate the expression 1+++2?  How many ever + I put in between, it is printing 3 as the answer. Please can anyone explain this behavior  And for 1--2 it is printing 3 and for 1---2 it is printing -1