mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2024-11-27 06:02:22 +00:00
Some cleanups
This commit is contained in:
parent
ccb46d7e3b
commit
f008cc257d
3 changed files with 35 additions and 11 deletions
1
ftepp.c
1
ftepp.c
|
@ -23,7 +23,6 @@
|
|||
*/
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "gmqcc.h"
|
||||
|
|
2
main.c
2
main.c
|
@ -21,8 +21,6 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
|
43
util.c
43
util.c
|
@ -22,10 +22,6 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
#define GMQCC_PLATFORM_HEADER
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "gmqcc.h"
|
||||
#include "platform.h"
|
||||
|
||||
|
@ -286,9 +282,40 @@ bool util_isatty(fs_file_t *file) {
|
|||
return false;
|
||||
}
|
||||
|
||||
void util_seed(uint32_t value) {
|
||||
srand((int)value);
|
||||
}
|
||||
/*
|
||||
* A small noncryptographic PRNG based on:
|
||||
* http://burtleburtle.net/bob/rand/smallprng.html
|
||||
*/
|
||||
static uint32_t util_rand_state[4] = {
|
||||
0xF1EA5EED, 0x00000000,
|
||||
0x00000000, 0x00000000
|
||||
};
|
||||
|
||||
#define util_rand_rot(X, Y) (((X)<<(Y))|((X)>>(32-(Y))))
|
||||
|
||||
uint32_t util_rand() {
|
||||
return rand();
|
||||
uint32_t last;
|
||||
|
||||
last = util_rand_state[0] - util_rand_rot(util_rand_state[1], 27);
|
||||
util_rand_state[0] = util_rand_state[1] ^ util_rand_rot(util_rand_state[2], 17);
|
||||
util_rand_state[1] = util_rand_state[2] + util_rand_state[3];
|
||||
util_rand_state[2] = util_rand_state[3] + last;
|
||||
util_rand_state[3] = util_rand_state[0] + last;
|
||||
|
||||
return util_rand_state[3];
|
||||
}
|
||||
|
||||
#undef util_rand_rot
|
||||
|
||||
void util_seed(uint32_t value) {
|
||||
size_t i;
|
||||
|
||||
util_rand_state[0] = 0xF1EA5EED;
|
||||
util_rand_state[1] = value;
|
||||
util_rand_state[2] = value;
|
||||
util_rand_state[3] = value;
|
||||
|
||||
for (i = 0; i < 20; ++i)
|
||||
(void)util_rand();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue