This content has been marked as final.
Show 22 replies

1. Re: Random Number Selection Help
843789 Dec 15, 2009 4:21 AM (in response to 843789)heck, I'd use a myRandom.nextBoolean() and mult 0.5 by 1 vs 1 if true vs false, then add. 
2. Re: Random Number Selection Help
843789 Dec 15, 2009 4:23 AM (in response to 843789)I can't work out whether you want
ordouble randomOne = myRandom.nextDouble()  0.5;
double randomOne = myRandom.nextInt(2)  0.5;

3. Re: Random Number Selection Help
843789 Dec 15, 2009 4:26 AM (in response to 843789)I will try out both of your suggestions and write back in a little bit if they work. I want to the program to randomly ADD .5 or SUBTRACT .5 to each trial.
I thought it would look something like this (but this does not work):
double randomOne = myRandom.nextDouble(.5  .5) 
4. Re: Random Number Selection Help
843789 Dec 15, 2009 4:30 AM (in response to 843789)s_cheplick12 wrote:
So you want my second solution or Enceph's solution.
I will try out both of your suggestions and write back in a little bit if they work. I want to the program to randomly ADD .5 or SUBTRACT .5 to each trial.
>I thought it would look something like this (but this does not work):
An interesting syntax!
double randomOne = myRandom.nextDouble(.5  .5) 
5. Re: Random Number Selection Help
843789 Dec 15, 2009 4:30 AM (in response to 843789)Neither suggestion worked the way I wanted them to. I will try to work out the myRandom.nextBoolean suggestion above, but I'm not sure thats what I am looking for. I'd rather use a myRandom.nextInt or myRandom.nextDouble and have the program randomly add or subtract .5 
6. Re: Random Number Selection Help
843789 Dec 15, 2009 4:31 AM (in response to 843789)Use suggestion in reply 1. Pseudocode:get random boolean; if random boolean { add 0.5; } else { subtract 0.5; }

7. Re: Random Number Selection Help
843789 Dec 15, 2009 4:33 AM (in response to 843789)sabre150 wrote:
Sabre,s_cheplick12 wrote:
So you want my second solution or Enceph's solution.
I will try out both of your suggestions and write back in a little bit if they work. I want to the program to randomly ADD .5 or SUBTRACT .5 to each trial.
I thought it would look something like this (but this does not work):
An interesting syntax!
double randomOne = myRandom.nextDouble(.5  .5)
I tried out using your two suggestions, and they did not work the way I wanted. I'll try the boolean suggestion mentioned above, and write back how that worked out.
double randomOne = myRandom.nextDouble(.5  .5)
I actually think that if Java did have the power to read code that way it would be great. 
8. Re: Random Number Selection Help
843789 Dec 15, 2009 4:34 AM (in response to 843789)s_cheplick12 wrote:
My second solution and Enceph's solution will both do what you have just asked for.
Neither suggestion worked the way I wanted them to.
I will try to work out the myRandom.nextBoolean suggestion above, but I'm not sure thats what I am looking for.
The we sure as hell have a problem with working out what you are looking for.
I'd rather use a myRandom.nextInt or myRandom.nextDouble and have the program randomly add or subtract .5
Maybe you would but you have to use what is available.
Random.nextInt(2) gives either 0 or 1 uniformly distributed (50% chance of each happening on any call). Subtracting 0.5 from this values gives either 0.5 or +0.5 . 
9. Re: Random Number Selection Help
843789 Dec 15, 2009 4:38 AM (in response to 843789)Sabre,
"Then we sure as hell have a problem with working out what you are looking for."
I'll try again. I must be moving to fast. I'll write back in a little bit and let you know how it worked. Stay tuned... 
10. Re: Random Number Selection Help
843789 Dec 15, 2009 4:38 AM (in response to 843789)Now I'm confused as to the requirements. Are your trying to randomly add/subtract 0.5 to a random number or to some other variable? 
11. Re: Random Number Selection Help
843789 Dec 15, 2009 4:46 AM (in response to 843789)I'm trying to randomly add or subtract .5 from the number 10 and see if it reaches 20 or 0 first. The purpose of my trial stems from a math project that I am working on. The program will end when it gets to 20 or 0 from a random process of adding or subtracting .5
note: I am a super newb at Java
Edited by: s_cheplick12 on Dec 14, 2009 8:46 PM 
12. Re: Random Number Selection Help
843789 Dec 15, 2009 4:48 AM (in response to 843789)s_cheplick12 wrote:
Then both Enceph's solution and my second solution will provide the random +0.5 or 0.5 that you need to ADD to the current summation at each iteration.
I'm trying to randomly add or subtract .5 from the number 10 and see if it reaches 20 or 0 first. The purpose of my trial stems from a math project that I am working on. The program will end when it gets to 20 or 0 from a random process of adding or subtracting .5
note: I am a super newb at Java
Edited by: s_cheplick12 on Dec 14, 2009 8:46 PM 
13. Re: Random Number Selection Help
843789 Dec 15, 2009 5:07 AM (in response to 843789)In that case I would go with sabre's second suggestion.value += myRandom.nextInt(2)  0.5;

14. Re: Random Number Selection Help
843789 Dec 15, 2009 5:12 AM (in response to 843789)Otherwise, you can save yourself a lot of trouble.
Since you are guaranteed one of only two possibilites ;)if(myRandom.nextBoolean()) { System.out.println(20); } else { System.out.println(0); }