/ Check-in [eb7a9c04]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Improved non-locking PRNG.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | begin-concurrent
Files: files | file ages | folders
SHA3-256: eb7a9c04bdbb297938672526d8c86b5666fb0f9841b9ddc2d9002399301cf665
User & Date: drh 2020-07-31 20:56:15
Context
2020-08-10
21:16
Merge recent trunk enhancements into begin-concurrent. (Leaf check-in: ed4c742c user: drh tags: begin-concurrent)
2020-07-31
20:56
Improved non-locking PRNG. (check-in: eb7a9c04 user: drh tags: begin-concurrent)
2020-07-30
19:19
Merge latest trunk changes into this branch. (check-in: e8a66515 user: dan tags: begin-concurrent)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/random.c.

118
119
120
121
122
123
124
125




126

127
128
129
130
131
132
133

/*
** Generate N bytes of pseudo-randomness using a FastPrng
*/
void sqlite3FastRandomness(FastPrng *pPrng, int N, void *P){
  unsigned char *pOut = (unsigned char*)P;
  while( N-->0 ){
    pPrng->x = ((pPrng->x)>>1) ^ ((1+~((pPrng->x)&1)) & 0xd0000001);




    pPrng->y = (pPrng->y)*1103515245 + 12345;

    *(pOut++) = (pPrng->x ^ pPrng->y) & 0xff;
  }
}

#ifndef SQLITE_UNTESTABLE
/*
** For testing purposes, we sometimes want to preserve the state of







|
>
>
>
>
|
>







118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138

/*
** Generate N bytes of pseudo-randomness using a FastPrng
*/
void sqlite3FastRandomness(FastPrng *pPrng, int N, void *P){
  unsigned char *pOut = (unsigned char*)P;
  while( N-->0 ){
    /* "x" is a variant of LFSR called "Xorshift" by George Marsaglia */
    pPrng->x ^= pPrng->x <<13;
    pPrng->x ^= pPrng->x >>7;
    pPrng->x ^= pPrng->x <<17;
    /* "y" is a LCG using Don Kunth's constants from MMIX */
    pPrng->y = (pPrng->y)*6364136223846793005LL + 1442695040888963407LL;
    /* XOR the two streams together to give the final result */
    *(pOut++) = (pPrng->x ^ pPrng->y) & 0xff;
  }
}

#ifndef SQLITE_UNTESTABLE
/*
** For testing purposes, we sometimes want to preserve the state of

Changes to src/sqliteInt.h.

1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
#endif

/*
** State of a simple PRNG used for the per-connection and per-pager
** pseudo-random number generators.
*/
struct FastPrng {
  unsigned int x, y;
};

/*
** Each database file to be accessed by the system is an instance
** of the following structure.  There are normally two of these structures
** in the sqlite.aDb[] array.  aDb[0] is the main database file and
** aDb[1] is the database file used to hold temporary tables.  Additional







|







1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
#endif

/*
** State of a simple PRNG used for the per-connection and per-pager
** pseudo-random number generators.
*/
struct FastPrng {
  sqlite3_uint64 x, y;
};

/*
** Each database file to be accessed by the system is an instance
** of the following structure.  There are normally two of these structures
** in the sqlite.aDb[] array.  aDb[0] is the main database file and
** aDb[1] is the database file used to hold temporary tables.  Additional