# need help, weird question kinda.

• 01-14-2008, 04:15 AM
carlos123
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
• 01-14-2008, 04:34 AM
CaptainMorgan
What have you got so far? (please remember to use code tags)
• 01-14-2008, 04:38 AM
carlos123
well i know how to get the time.

Quote:

int sec = cal.get(Calendar.SECOND);
• 01-14-2008, 04:52 AM
CaptainMorgan
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.
• 01-14-2008, 05:07 AM
carlos123
Quote:

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?
• 01-17-2008, 11:45 PM
carlos123
eh, any suggestions? ^^
• 01-22-2008, 04:19 AM
gibsonrocker800
well you could use a while loop until the number is between 20.

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?