Add a new api sqlite3_randomness() for providing access to SQLite's
internal PRNG. Add sqlite3_test_control() verbs for controlling the PRNG. (CVS 4882) FossilOrigin-Name: 15110ea02768bfe977a57eccd6b941a36ebd6b32
This commit is contained in:
+5
-5
@@ -16,7 +16,7 @@
|
||||
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
|
||||
** All other code has file scope.
|
||||
**
|
||||
** $Id: func.c,v 1.186 2008/03/06 09:58:50 mlcreech Exp $
|
||||
** $Id: func.c,v 1.187 2008/03/19 14:15:34 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
@@ -323,7 +323,7 @@ static void randomFunc(
|
||||
sqlite3_value **argv
|
||||
){
|
||||
sqlite_int64 r;
|
||||
sqlite3Randomness(sizeof(r), &r);
|
||||
sqlite3_randomness(sizeof(r), &r);
|
||||
if( (r<<1)==0 ) r = 0; /* Prevent 0x8000.... as the result so that we */
|
||||
/* can always do abs() of the result */
|
||||
sqlite3_result_int64(context, r);
|
||||
@@ -351,7 +351,7 @@ static void randomBlob(
|
||||
}
|
||||
p = contextMalloc(context, n);
|
||||
if( p ){
|
||||
sqlite3Randomness(n, p);
|
||||
sqlite3_randomness(n, p);
|
||||
sqlite3_result_blob(context, (char*)p, n, sqlite3_free);
|
||||
}
|
||||
}
|
||||
@@ -1047,12 +1047,12 @@ static void randStr(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
if( iMax>=sizeof(zBuf) ) iMax = sizeof(zBuf)-1;
|
||||
n = iMin;
|
||||
if( iMax>iMin ){
|
||||
sqlite3Randomness(sizeof(r), &r);
|
||||
sqlite3_randomness(sizeof(r), &r);
|
||||
r &= 0x7fffffff;
|
||||
n += r%(iMax + 1 - iMin);
|
||||
}
|
||||
assert( n<sizeof(zBuf) );
|
||||
sqlite3Randomness(n, zBuf);
|
||||
sqlite3_randomness(n, zBuf);
|
||||
for(i=0; i<n; i++){
|
||||
zBuf[i] = zSrc[zBuf[i]%(sizeof(zSrc)-1)];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user