# Thread: need help, weird question kinda.

1. Member
Join Date
Nov 2007
Posts
38
Rep Power
0

## need help, weird question kinda.

basicly what i need is some code that takes the current time, and gets the seconds and divides it by 3 and rounds it so its a whole number between 1-20

2. What have you got so far? (please remember to use code tags)

3. Member
Join Date
Nov 2007
Posts
38
Rep Power
0
well i know how to get the time.

int sec = cal.get(Calendar.SECOND);

4. Fair enough, so there's 60 seconds in a minute, right? You have a variable that represents the current seconds', take that value and divide it by three and use I believe Math.round() -> or something to that effect, I'm not sure of the exact use but there is one in the API. If you divide 60 by 3 that result has to be 20 or less by the operation rule you performed. For example, if (sec == 42) and (42 / 3) = 14 finally, 14 < 20.

5. Member
Join Date
Nov 2007
Posts
38
Rep Power
0
int sec = cal.get(Calendar.SECOND);
int sec2 = sec / 3;
int sec3 = Math.round(sec2);
ok now i need to put this through an equation that makes it psuedorandom because my assignment is to generate 10,000 numbers 1-20, i got the seed, now i need help with an equation to put it through to keep it 1-20, any suggestions?

6. Member
Join Date
Nov 2007
Posts
38
Rep Power
0
eh, any suggestions? ^^

7. well you could use a while loop until the number is between 20.

Java Code:
```boolean done = false;
while(!done)
{
int sec = cal.get(Calendar.SECOND);
int sec2 = sec / 3;
int sec3 = Math.round(sec2);

if(sec3 >= 1 && sec3 <= 20)
done = true;

}```
Now, it does the process until the final number is between 1 and 20.

Does this help?

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•