NO

Author Topic: Pseudo random number generator  (Read 2303 times)

Grincheux

  • Guest
Pseudo random number generator
« on: March 18, 2016, 05:35:07 AM »
You will laught seeing my algo, but it works.
With scientist rng I got numbers but between two numbers ther was not enougth space.

See my code :

Code: [Select]
int Random(int __Maximum)
{
SYSTEMTIME _St ;
char _szTmp[256] ;
int _iResult ;

GetLocalTime(&_St) ;

wsprintf(_szTmp,"%u%u",_St.wMilliseconds,_St.wSecond) ;
_iResult = atoi(_szTmp) ;
if(_iResult < 0) _iResult *= -1 ;
if(_iResult == 0) _iResult = 24121959 ;

return (_iResult % __Maximum) ;
}

It is base on the LocalTime function.
I need to generate numbers between 1..9, 1..64,  1..625, 1..9072 and 1.. 117649

I spend lot of hours googling, but no result available in my case.
An other idea was to create a timer that increase à variable, I read it and apply a modulo. Finally the first solution was the easier one.

If the result is 0 I set to my birthday date.
If the result is less than 0, I mutiply by -1.

I tried with rand() but not good in my case.

Now you can laught I allow you... ;D ;D ;D ;D ;D
« Last Edit: March 18, 2016, 05:41:17 AM by Grincheux »