You (DFS) replied ( to me ):
> > #define Rand( Min, Max ) ( Min + ( Max - Min )*rand()/RAND_MAX )
>
> Have you tested this?
> It always returns 1, so I get results like this when building a random
> date in the range of (2023,2026).
Right, it should've been: "float( Max - Min )*rand()/RAND_MAX".
wchar_t Out[ 400 ], *D = Out; __int64 RandDay, RandTime, Min, Max ;
tm rRandTime, rTimeB = {}, rTimeE ;
float TotalSeconds, TotalDays, SecsPerDay = 24.*60*60 ;
const int StartYear = 2023, Years = 4, szBucket = 15*Years ;
rTimeB.tm_mday = 1, rTimeB.tm_year = StartYear - 1900, rTimeB.tm_isdst = -1 ;
rTimeE = rTimeB, rTimeE.tm_year += Years ;
Min = mktime( &rTimeB ), Max = mktime( &rTimeE );
TotalDays = TotalSeconds = Max - Min, TotalDays /= SecsPerDay ;
const int iterations = TotalDays/szBucket ;
int Bucket[366*Years/szBucket] = {};
LoopJ(2000000) { RandTime = RandDay = TotalSeconds*rand()/RAND_MAX, RandTime += Min ;
RandDay /= SecsPerDay, rRandTime = *localtime( ( time_t * ) &RandTime );
Bucket[ RandDay/szBucket ]++ ; }
LoopK(iterations) D += swprintf( D, L"%5d, ", Bucket[ K ] ); Sh( L"%s\n\n", Out );
// Output, each bucket holds 60 days (15*Years):
//
// 82306, 82091, 82080, 81876, 81668, 82360, 81806, 81960, 82504, 82301, 82502, 82043
// 82024, 81927, 82602, 82453, 81705, 82287, 82075, 82423, 82414, 82181, 82161, 81711