mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-10 01:29:05 -04:00
replace random() with rand() for windows goodness
This commit is contained in:
parent
613d437b87
commit
4f1de02710
@ -135,8 +135,8 @@ get_ships(struct notcurses* nc, struct ship* ships, unsigned shipcount){
|
||||
return -1;
|
||||
}
|
||||
struct ncvisual_options vopts = {
|
||||
.y = 30,//random() % (ncplane_dim_y(notcurses_stdplane_const(nc)) - SHIPHEIGHT),
|
||||
.x = 30,//random() % (ncplane_dim_x(notcurses_stdplane_const(nc)) - SHIPWIDTH),
|
||||
.y = 30,//rand() % (ncplane_dim_y(notcurses_stdplane_const(nc)) - SHIPHEIGHT),
|
||||
.x = 30,//rand() % (ncplane_dim_x(notcurses_stdplane_const(nc)) - SHIPWIDTH),
|
||||
.blitter = NCBLIT_PIXEL,
|
||||
.flags = NCVISUAL_OPTION_NODEGRADE,
|
||||
};
|
||||
@ -149,10 +149,10 @@ get_ships(struct notcurses* nc, struct ship* ships, unsigned shipcount){
|
||||
}
|
||||
}
|
||||
ncplane_move_below(ships[s].n, notcurses_stdplane(nc));
|
||||
if((ships[s].vely = random() % 6 - 3) == 0){
|
||||
if((ships[s].vely = rand() % 6 - 3) == 0){
|
||||
ships[s].vely = 3;
|
||||
}
|
||||
if((ships[s].velx = random() % 6 - 3) == 0){
|
||||
if((ships[s].velx = rand() % 6 - 3) == 0){
|
||||
ships[s].velx = 3;
|
||||
}
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ eagles(struct notcurses* nc, struct ncplane* n){
|
||||
} e[3];
|
||||
for(size_t i = 0 ; i < sizeof(e) / sizeof(*e) ; ++i){
|
||||
e[i].xoff = 0;
|
||||
e[i].yoff = random() % ((truey - height) / 2);
|
||||
e[i].yoff = rand() % ((truey - height) / 2);
|
||||
struct ncplane_options nopts = {
|
||||
.y = e[i].yoff,
|
||||
.x = e[i].xoff,
|
||||
@ -193,14 +193,14 @@ eagles(struct notcurses* nc, struct ncplane* n){
|
||||
if(e[i].xoff >= truex){
|
||||
continue;
|
||||
}
|
||||
e[i].yoff += random() % (2 + i) - 1;
|
||||
e[i].yoff += rand() % (2 + i) - 1;
|
||||
if(e[i].yoff < 0){
|
||||
e[i].yoff = 0;
|
||||
}else if(e[i].yoff + height >= truey){
|
||||
e[i].yoff = truey - height - 1;
|
||||
}
|
||||
int scale = truex >= 80 ? truex / 80 : 1;
|
||||
e[i].xoff += (random() % scale) + 1;
|
||||
e[i].xoff += (rand() % scale) + 1;
|
||||
ncplane_move_yx(e[i].n, e[i].yoff, e[i].xoff);
|
||||
++eaglesmoved;
|
||||
}
|
||||
|
@ -129,8 +129,8 @@ int fission_demo(struct notcurses* nc){
|
||||
continue;
|
||||
}
|
||||
int newy, newx;
|
||||
newy = random() % (maxy - 1) + 2;
|
||||
newx = random() % (maxx - 1) + 2;
|
||||
newy = rand() % (maxy - 1) + 2;
|
||||
newx = rand() % (maxx - 1) + 2;
|
||||
if(x + newx >= dimx){
|
||||
newx = dimx - x;
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "demo.h"
|
||||
#include <sys/random.h>
|
||||
|
||||
int qrcode_demo(struct notcurses* nc){
|
||||
if(!notcurses_canutf8(nc)){
|
||||
@ -13,11 +12,11 @@ int qrcode_demo(struct notcurses* nc){
|
||||
struct ncplane* n = ncplane_dup(stdn, NULL);
|
||||
for(int i = 0 ; i < 1024 ; ++i){
|
||||
ncplane_erase(n);
|
||||
size_t len = random() % sizeof(data) + 1;
|
||||
size_t len = rand() % sizeof(data) + 1;
|
||||
size_t done = 0;
|
||||
// done this tedious way because getrandom() doesn't exist on freebsd 11
|
||||
// done this tedious way because getrand() doesn't exist on freebsd 11
|
||||
while(done < len){
|
||||
long r = random();
|
||||
long r = rand();
|
||||
memcpy(data + done, &r, sizeof(r));
|
||||
done += sizeof(r);
|
||||
}
|
||||
@ -28,7 +27,7 @@ int qrcode_demo(struct notcurses* nc){
|
||||
if(qlen > 0){ // FIXME can fail due to being too large for display; distinguish this case
|
||||
ncplane_move_yx(n, (dimy - y) / 2, (dimx - x) / 2);
|
||||
ncplane_home(n);
|
||||
ncplane_set_fg_rgb8(n, random() % 255 + 1, random() % 255 + 1, random() % 255 + 1);
|
||||
ncplane_set_fg_rgb8(n, rand() % 255 + 1, rand() % 255 + 1, rand() % 255 + 1);
|
||||
DEMO_RENDER(nc);
|
||||
}
|
||||
}
|
||||
|
@ -121,10 +121,10 @@ tablet_thread(void* vtabletctx){
|
||||
tabletctx* tctx = vtabletctx;
|
||||
while(true){
|
||||
struct timespec ts;
|
||||
ts.tv_sec = random() % 2 + MINSECONDS;
|
||||
ts.tv_nsec = random() % 1000000000;
|
||||
ts.tv_sec = rand() % 2 + MINSECONDS;
|
||||
ts.tv_nsec = rand() % 1000000000;
|
||||
nanosleep(&ts, NULL);
|
||||
int action = random() % 5;
|
||||
int action = rand() % 5;
|
||||
pthread_mutex_lock(&tctx->lock);
|
||||
if(action < 2){
|
||||
tctx->lines -= (action + 1);
|
||||
@ -156,8 +156,8 @@ new_tabletctx(struct ncreel* pr, unsigned *id){
|
||||
}
|
||||
pthread_mutex_init(&tctx->lock, NULL);
|
||||
tctx->pr = pr;
|
||||
tctx->lines = random() % 10 + 2; // FIXME a nice gaussian would be swell
|
||||
tctx->rgb = random() % (1u << 24u);
|
||||
tctx->lines = rand() % 10 + 2; // FIXME a nice gaussian would be swell
|
||||
tctx->rgb = rand() % (1u << 24u);
|
||||
tctx->id = ++*id;
|
||||
if((tctx->t = ncreel_add(pr, NULL, NULL, drawcb, tctx)) == NULL){
|
||||
pthread_mutex_destroy(&tctx->lock);
|
||||
|
@ -50,7 +50,7 @@ play(struct notcurses* nc, struct ncplane** chunks){
|
||||
const uint64_t totalns = delayns * 5;
|
||||
const uint64_t deadline_ns = timespec_to_ns(&cur) + totalns;
|
||||
const uint64_t movens = totalns / MOVES;
|
||||
int hole = random() % chunkcount;
|
||||
int hole = rand() % chunkcount;
|
||||
int holex, holey;
|
||||
ncplane_yx(chunks[hole], &holey, &holex);
|
||||
ncplane_destroy(chunks[hole]);
|
||||
@ -66,7 +66,7 @@ play(struct notcurses* nc, struct ncplane** chunks){
|
||||
int mover = chunkcount;
|
||||
int direction;
|
||||
do{
|
||||
direction = random() % 4;
|
||||
direction = rand() % 4;
|
||||
switch(direction){
|
||||
case 3: // up
|
||||
if(lastdir != 1 && hole >= CHUNKS_HORZ){ mover = hole - CHUNKS_HORZ; } break;
|
||||
@ -199,10 +199,10 @@ int sliding_puzzle_demo(struct notcurses* nc){
|
||||
int i;
|
||||
demo_nanosleep(nc, &demodelay);
|
||||
for(i = 0 ; i < 200 ; ++i){
|
||||
int i0 = random() % chunkcount;
|
||||
int i1 = random() % chunkcount;
|
||||
int i0 = rand() % chunkcount;
|
||||
int i1 = rand() % chunkcount;
|
||||
while(i1 == i0){
|
||||
i1 = random() % chunkcount;
|
||||
i1 = rand() % chunkcount;
|
||||
}
|
||||
int targy0, targx0;
|
||||
int targy, targx;
|
||||
|
@ -103,8 +103,8 @@ slidepanel(struct notcurses* nc, struct ncplane* stdn){
|
||||
notcurses_term_dim_yx(nc, &dimy, &dimx);
|
||||
int ny = dimy / 4;
|
||||
int nx = dimx / 3;
|
||||
int yoff = random() % (dimy - ny - 2) + 1; // don't start atop a border
|
||||
int xoff = random() % (dimx - nx - 2) + 1;
|
||||
int yoff = rand() % (dimy - ny - 2) + 1; // don't start atop a border
|
||||
int xoff = rand() % (dimx - nx - 2) + 1;
|
||||
struct ncplane* l;
|
||||
|
||||
// First we just create a plane with no styling and no glyphs.
|
||||
@ -125,8 +125,8 @@ slidepanel(struct notcurses* nc, struct ncplane* stdn){
|
||||
ncplane_set_base_cell(n, &c);
|
||||
clock_gettime(CLOCK_MONOTONIC, &cur);
|
||||
uint64_t deadlinens = timespec_to_ns(&cur) + timespec_to_ns(&demodelay);
|
||||
int velx = random() % 4 + 1;
|
||||
int vely = random() % 4 + 1;
|
||||
int velx = rand() % 4 + 1;
|
||||
int vely = rand() % 4 + 1;
|
||||
l = legend(nc, "default background, all opaque, whitespace glyph");
|
||||
int err = slideitslideit(nc, n, deadlinens, &vely, &velx);
|
||||
if(err){
|
||||
|
@ -83,7 +83,7 @@ draw_block(struct ncplane* nn, uint32_t blockstart){
|
||||
// see https://github.com/dankamongmen/notcurses/issues/259. we use a random
|
||||
// (but dark) background for the perimeter to force refreshing on the box,
|
||||
// when it might otherwise be molested by RTL text. hacky and gross :( FIXME
|
||||
int rbg = random() % 20;
|
||||
int rbg = rand() % 20;
|
||||
nccell_set_bg_rgb(&ul, rbg);
|
||||
nccell_set_bg_rgb(&ur, rbg);
|
||||
nccell_set_bg_rgb(&ll, rbg);
|
||||
|
@ -77,8 +77,8 @@ typedef struct worm {
|
||||
static void
|
||||
init_worm(worm* s, int dimy, int dimx){
|
||||
nccell_init(&s->lightup);
|
||||
s->y = random() % dimy;
|
||||
s->x = random() % dimx;
|
||||
s->y = rand() % dimy;
|
||||
s->x = rand() % dimx;
|
||||
s->prevx = 0;
|
||||
s->prevy = 0;
|
||||
}
|
||||
@ -101,7 +101,7 @@ wormy(worm* s, int dimy, int dimx){
|
||||
do{ // force a move
|
||||
s->y = oldy;
|
||||
s->x = oldx;
|
||||
int direction = random() % 4;
|
||||
int direction = rand() % 4;
|
||||
switch(direction){
|
||||
case 0: --s->y; break;
|
||||
case 1: ++s->x; break;
|
||||
@ -481,7 +481,7 @@ int witherworm_demo(struct notcurses* nc){
|
||||
}
|
||||
ncplane_set_bg_rgb8(n, 20, 20, 20);
|
||||
do{ // we fill up the screen, however large, bouncing around our strtable
|
||||
s = strs + random() % ((sizeof(strs) / sizeof(*strs)) - 1);
|
||||
s = strs + rand() % ((sizeof(strs) / sizeof(*strs)) - 1);
|
||||
size_t idx = 0;
|
||||
ncplane_cursor_yx(n, &y, &x);
|
||||
while((*s)[idx]){ // each multibyte char of string
|
||||
|
@ -84,8 +84,8 @@ int yield_demo(struct notcurses* nc){
|
||||
int pfilled = 0;
|
||||
do{
|
||||
++iters;
|
||||
int x = random() % maxx;
|
||||
int y = random() % maxy;
|
||||
int x = rand() % maxx;
|
||||
int y = rand() % maxy;
|
||||
uint32_t pixel = 0;
|
||||
if(ncvisual_at_yx(wmv, y, x, &pixel) < 0){
|
||||
ncvisual_destroy(wmv);
|
||||
@ -99,7 +99,7 @@ int yield_demo(struct notcurses* nc){
|
||||
continue;
|
||||
}
|
||||
ncpixel_set_a(&pixel, 0xfe);
|
||||
ncpixel_set_rgb8(&pixel, (random() % 128) + 128, 0, ncpixel_b(pixel) / 4);
|
||||
ncpixel_set_rgb8(&pixel, (rand() % 128) + 128, 0, ncpixel_b(pixel) / 4);
|
||||
pfilled = ncvisual_polyfill_yx(wmv, y, x, pixel);
|
||||
if(pfilled < 0){
|
||||
ncvisual_destroy(wmv);
|
||||
|
@ -33,12 +33,12 @@ print_gb(struct ncdirect* nc, int r, int total){
|
||||
|
||||
static int
|
||||
print_rgb8(struct ncdirect* nc, int total){
|
||||
if(random() % 2){
|
||||
if(rand() % 2){
|
||||
if(ncdirect_off_styles(nc, NCSTYLE_ITALIC)){
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if(random() % 16 == 0){
|
||||
if(rand() % 16 == 0){
|
||||
if(ncdirect_on_styles(nc, NCSTYLE_ITALIC)){
|
||||
return -1;
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
int main(void){
|
||||
srand(time(NULL)); // gross
|
||||
long guess, secret = random();
|
||||
long guess, secret = rand();
|
||||
struct ncdirect* n = ncdirect_core_init(NULL, stdout, NCDIRECT_OPTION_INHIBIT_CBREAK);
|
||||
if(n == NULL){
|
||||
return EXIT_FAILURE;
|
||||
|
@ -12,7 +12,7 @@ handle(struct notcurses* nc, const char *fn){
|
||||
struct ncplane* stdn = notcurses_stddim_yx(nc, &dimy, &dimx);
|
||||
for(int y = 0 ; y < dimy ; y += 15){
|
||||
for(int x = 0 ; x < dimx ; x += 15){
|
||||
uint64_t channels = NCCHANNELS_INITIALIZER(random() % 256, random() % 256, 100, random() % 256, 100, 140);
|
||||
uint64_t channels = NCCHANNELS_INITIALIZER(rand() % 256, rand() % 256, 100, rand() % 256, 100, 140);
|
||||
ncplane_set_base(stdn, "a", 0, channels);
|
||||
struct ncvisual_options vopts = {
|
||||
.y = y,
|
||||
@ -27,7 +27,7 @@ handle(struct notcurses* nc, const char *fn){
|
||||
}
|
||||
notcurses_render(nc);
|
||||
sleep(1);
|
||||
channels = NCCHANNELS_INITIALIZER(random() % 256, random() % 256, 100, random() % 256, 100, 140);
|
||||
channels = NCCHANNELS_INITIALIZER(rand() % 256, rand() % 256, 100, rand() % 256, 100, 140);
|
||||
ncplane_set_base(stdn, "a", 0, channels);
|
||||
notcurses_render(nc);
|
||||
sleep(1);
|
||||
|
@ -486,7 +486,7 @@ TEST_CASE("Bitmaps") {
|
||||
auto x = 2 * nc_->tcache.cellpixx;
|
||||
std::vector<uint32_t> v(x * y, htole(0xffffffff));
|
||||
for(auto& e : v){
|
||||
e -= htole(random() % 0x1000000);
|
||||
e -= htole(rand() % 0x1000000);
|
||||
}
|
||||
auto ncv = ncvisual_from_rgba(v.data(), y, sizeof(decltype(v)::value_type) * x, x);
|
||||
REQUIRE(nullptr != ncv);
|
||||
@ -524,7 +524,7 @@ TEST_CASE("Bitmaps") {
|
||||
auto x = 10 * nc_->tcache.cellpixx;
|
||||
std::vector<uint32_t> v(x * y, htole(0xffffffff));
|
||||
for(auto& e : v){
|
||||
e -= htole(random() % 0x1000000);
|
||||
e -= htole(rand() % 0x1000000);
|
||||
}
|
||||
auto ncv = ncvisual_from_rgba(v.data(), y, sizeof(decltype(v)::value_type) * x, x);
|
||||
REQUIRE(nullptr != ncv);
|
||||
|
@ -10,12 +10,12 @@ std::unique_ptr<ncpp::Plane> NewPiece() {
|
||||
} tetriminos[] = { // OITLJSZ
|
||||
{ 0xcbc900, "****"}, { 0x009caa, " ****"}, { 0x952d98, " * ***"}, { 0xcf7900, " ****"},
|
||||
{ 0x0065bd, "* ***"}, { 0x69be28, " **** "}, { 0xbd2939, "** **"} };
|
||||
const int tidx = random() % 7;
|
||||
const int tidx = rand() % 7;
|
||||
const struct tetrimino* t = &tetriminos[tidx];
|
||||
const size_t cols = strlen(t->texture);
|
||||
int y, x;
|
||||
stdplane_->get_dim(&y, &x);
|
||||
const int xoff = x / 2 - BOARD_WIDTH + 2 * (random() % (BOARD_WIDTH / 2));
|
||||
const int xoff = x / 2 - BOARD_WIDTH + 2 * (rand() % (BOARD_WIDTH / 2));
|
||||
std::unique_ptr<ncpp::Plane> n = std::make_unique<ncpp::Plane>(2, cols, board_top_y_ - 1, xoff, nullptr);
|
||||
if(n){
|
||||
uint64_t channels = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user