1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-11 01:42:22 +03:00

Enhance sqlite3_randomness(N,P) such that it resets the internal PRNG

if N is less than 1.  Subsequent calls to sqlite3_randomness() will reinitialize
the internal PRNG by calling the xRandomness() method of the default VFS.

FossilOrigin-Name: a221aa82bb5496885fd0bf76e4601443799511de
This commit is contained in:
drh
2014-01-01 14:00:13 +00:00
parent 3312348cf8
commit fe98081e18
6 changed files with 26 additions and 21 deletions

View File

@@ -52,6 +52,12 @@ void sqlite3_randomness(int N, void *pBuf){
sqlite3_mutex_enter(mutex);
#endif
if( N<=0 ){
wsdPrng.isInit = 0;
sqlite3_mutex_leave(mutex);
return;
}
/* Initialize the state of the random number generator once,
** the first time this routine is called. The seed value does
** not need to contain a lot of randomness since we are not
@@ -79,7 +85,8 @@ void sqlite3_randomness(int N, void *pBuf){
wsdPrng.isInit = 1;
}
while( N-- ){
assert( N>0 );
do{
wsdPrng.i++;
t = wsdPrng.s[wsdPrng.i];
wsdPrng.j += t;
@@ -87,7 +94,7 @@ void sqlite3_randomness(int N, void *pBuf){
wsdPrng.s[wsdPrng.j] = t;
t += wsdPrng.s[wsdPrng.i];
*(zBuf++) = wsdPrng.s[t];
}
}while( --N );
sqlite3_mutex_leave(mutex);
}
@@ -116,7 +123,4 @@ void sqlite3PrngRestoreState(void){
sizeof(sqlite3Prng)
);
}
void sqlite3PrngResetState(void){
GLOBAL(struct sqlite3PrngType, sqlite3Prng).isInit = 0;
}
#endif /* SQLITE_OMIT_BUILTIN_TEST */