I need to generate a random number for seconds and then take the seconds and calculate how many minutes and hours are those seconds. So, I generate a number first using rand(), but it seems kinda weird, every time I run the program, the random number (previous) just increases by 3. Yes, it's random, but still only increases by 3 every next run. I'd like to make it more random if possible.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
long sekundi;
srand(time(NULL));
sekundi = rand();
double minuti,casovi;
casovi = (sekundi / 3600);
minuti = (sekundi / 60);
printf("%d \n",sekundi);
printf("%4.2f \n",casovi);
printf("%4.2f \n",minuti);
return 0;
}
That's my code, I'm new to C please excuse my formatting and everything. It doesn't seem to calculate the hours and minutes correctly, it does correct for the first number and then adds x,00 after the number without correct decimal numbers.