clean scratchpad, start quickselect
This commit is contained in:
parent
65007a6304
commit
4a24a6b935
|
@ -1,27 +0,0 @@
|
||||||
|
|
||||||
uint64_t xorshift64(uint64_t* seed)
|
|
||||||
{
|
|
||||||
// Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs"
|
|
||||||
// <https://en.wikipedia.org/wiki/Xorshift>
|
|
||||||
uint64_t x = *seed;
|
|
||||||
x ^= x << 13;
|
|
||||||
x ^= x >> 7;
|
|
||||||
x ^= x << 17;
|
|
||||||
return *seed = x;
|
|
||||||
}
|
|
||||||
|
|
||||||
double sample_unit_uniform(uint64_t* seed)
|
|
||||||
{
|
|
||||||
// samples uniform from [0,1] interval.
|
|
||||||
return ((double)xorshift64(seed)) / ((double)UINT64_MAX);
|
|
||||||
}
|
|
||||||
|
|
||||||
double sample_unit_normal(uint64_t* seed)
|
|
||||||
{
|
|
||||||
// // See: <https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform>
|
|
||||||
double u1 = sample_unit_uniform(seed);
|
|
||||||
double u2 = sample_unit_uniform(seed);
|
|
||||||
double z = sqrtf(-2.0 * log(u1)) * sin(2 * PI * u2);
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
5
scratchpad/quickselect/makefile
Normal file
5
scratchpad/quickselect/makefile
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
build:
|
||||||
|
gcc quickselect.c -lm -o quickselect
|
||||||
|
|
||||||
|
run:
|
||||||
|
./quickselect
|
BIN
scratchpad/quickselect/quickselect
Executable file
BIN
scratchpad/quickselect/quickselect
Executable file
Binary file not shown.
8
scratchpad/quickselect/quickselect.c
Normal file
8
scratchpad/quickselect/quickselect.c
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
printf("Hello world!\n");
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user