VgaGames4 - random man-pages

[.. upper level ..]

Random functions

Create random numbers, also suitable for network-games. Network-suitable random numbers must generate the same number on every client. The start-number will be at initialization generated randomly (but equally for each client), so that there is always another sequence of numbers for each new game-start.


Example


/* print random numbers */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include <vgagames4.h>

int main(int argc, char **argv) {
  int inr;
  unsigned int rno1, rno2;

  (void)argc; (void)argv;

  /* initialize VgaGames library */
  if (!VG_init("window-example")) { exit(1); }

  /* print random numbers for two scopes */
  for (inr = 1; inr <= 10; inr++) {
    rno1 = vg4->random->get("SCOPE1", 0, 99);
    rno2 = vg4->random->get("SCOPE2", 0, 99);
    printf("%d:\n", inr);
    printf(" - SCOPE1: %u\n", rno1);
    printf(" - SCOPE2: %u\n", rno2);
  }

  /* destroy and exit */
  VG_dest();
  exit(0);
}