Generating random numbers
Hi,
I am currently taking a Java based computer science paper at University and am a beginner.
My current assignment is writing a share trading program where users can decide how many of each type of share they would like to buy/sell and there are 5 time periods.
The value of each share (there are 3 types) at the start is a random value of either 5,6,7,8 or 9. In each new time period, the value of each type of share should either increase by 1, decrease by 1 or remain unchanged, and the change which occurs is random. So I have to generate a random number of -1, 0 or 1 to add to the values from the previous period.
So finally, my question. I know how to use Math.random to get 0 or 1, but how can I also randomly generate a negative number?
Thanks in advance for any help.
|