Results 1 to 7 of 7
Thread: random
- 09-29-2012, 10:57 PM #1
Member
- Join Date
- Jul 2012
- Posts
- 93
- Rep Power
- 0
- 09-29-2012, 11:06 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 785
- Rep Power
- 12
Re: random
Random (Java Platform SE 6)
Use the other constructor :)Random (Java Platform SE 6)
- 09-29-2012, 11:08 PM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 18
Re: random
Why does this keep printing 60?
- 09-29-2012, 11:14 PM #4
Member
- Join Date
- Jul 2012
- Posts
- 93
- Rep Power
- 0
- 09-29-2012, 11:16 PM #5
Member
- Join Date
- Jul 2012
- Posts
- 93
- Rep Power
- 0
Re: random
I think 0 is also OK.
- 09-29-2012, 11:21 PM #6
Member
- Join Date
- Mar 2012
- Posts
- 88
- Rep Power
- 0
Re: random
Hey mate,
Take out the 0 in your 1st line of code and see what happens....
- 09-30-2012, 12:27 AM #7
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 18
Re: random
I need it to random between 0 and 150. That's why I am using the seed. Shouldn't this print a different point between 1 and 150 every time.
The effect of the seed is described in the API docs: it sets "the initial value of the internal state of the pseudorandom number generator". From our point of view the pseudorandom number generator is something of a "black box". That is, it is completely deterministic but we have no idea what it does to create the sequence of numbers. It does, however, have a state and to say that it is deterministic is to say that the sequence it comes up with depends (only) on its state.
Since you are using the constructor which takes a seed argument, the initial state of the PRNG each time you run the program will be the same. And since (being deterministic) its subsequent behaviour depends only on its state, you are going to get the same pseudorandom sequence of values each time you run the program.
---
You can read about pseudorandom number generators like the one you are using at Wikipedia.
---
As others have said, don't use the form of the constructor that takes a seed argument.Last edited by pbrockway2; 09-30-2012 at 12:39 AM. Reason: third thoughts
Similar Threads
-
Using java.util.Random to choose a random sentence and print it
By skylerrivera17 in forum New To JavaReplies: 0Last Post: 01-23-2012, 10:12 AM -
Random Generation Not being random
By Mmarzex in forum New To JavaReplies: 8Last Post: 08-04-2011, 11:53 PM -
how i use the random class to random the cards i have
By yanipao in forum New To JavaReplies: 14Last Post: 10-19-2009, 11:57 AM -
How do I generate random numbers in a certain range using the random class?
By frasifrasi in forum New To JavaReplies: 8Last Post: 04-19-2009, 06:50 PM -
random numbers without random class`
By carlos123 in forum New To JavaReplies: 4Last Post: 01-17-2008, 11:44 PM
Bookmarks