Ejemplo n.º 1
0
int scGeneralGetRandStr( BYTE *data, int len )
{
#if defined(HAVE_LIBCRYPT)
	cryptGetRandom( data, len );
#elif defined(__palmos__)
	SysRandom( TimGetTicks() );

	while( len-- ){
		*data++ = SysRandom(0) & 0xFF;
	}
#elif defined(__linux__)
	FILE *fptr;

	fptr = fopen( "/dev/urandom", "rb" );
	if( fptr==NULL ) return( SC_EXIT_UNKNOWN_ERROR );

	if( fread( data, 1, len, fptr )!=len ) return( SC_EXIT_UNKNOWN_ERROR );
#else
	srand( time( NULL ) );

	while( len-- ){
		*data++ = rand() & 0xFF;
	}
#endif /* HAVE_LIBCRYPT */

	return( SC_EXIT_OK );
}
Ejemplo n.º 2
0
Archivo: game.c Proyecto: docwhat/cwimp
// ToDo: Clean up and make sure numbers are fairly random
int RollCube (void)
{
  int n = 0;
  //  char tmp[255]; // Debug

  n = ((SysRandom(0) %6) + 1);

  while (n == 0)
    {
      n = ((SysRandom(0) % 6) + 1);
    }
  
  //  SetFieldTextFromStr(statusLine, "StatusLineHereDoh!");
  return n;
}
Ejemplo n.º 3
0
static void playKeepEupEGame(void)
{
   // add new shape
   keepEupEShapeList[keepEupEShapeListLast] = SysRandom(0) % MAXKEEPEUPESHAPES;
   keepEupEShapeListLast++;

   // check for win
   if (keepEupEShapeListLast>=MAXKEEPEUPES){
      displayWinDialog();
      startKeepEupEGame();
   }
   else{
      int s;
      // play sounds + flash shapes (with delay)
      for(s=0;s<keepEupEShapeListLast;s++){
         flashShape(keepEupEShapeList[s],&WinEraseLineF);
         playFreq(sndCmdFreqDurationAmp/*sndCmdFrqOn*/, // I don't think it does block?, ohhh .. obviously not if sound off!
            keepEupENotes[keepEupEShapeList[s]],300); // TBD: make 300 decrease to go faster

         flashShape(keepEupEShapeList[s],&WinDrawLineF);
         // pause to break each shape apart (in case same shape important)
         SysTaskDelay((200 * SysTicksPerSecond())/1000);

      }
      // put user back to zero
      keepEupEShapeListUserIndex=0;
   }
}
Ejemplo n.º 4
0
Short dice(Short n, Short x)
{
  Short i, total = 0;
  for (i = 0 ; i < n ; i++)
    total += (SysRandom(0) % x) + 1;
  return total;
}
Ejemplo n.º 5
0
/***********************************************************************
 * function is called at program start
 * you can put your own initialization jobs there
 ***********************************************************************/
static UInt16
StartApplication(void)
{
  Err err = 0;

  // Initialize the random number seed;
  SysRandom( TimGetSeconds() );

  // Load prefs
  PrefLoadPrefs(&gPrefs);

  // Initialize TNglue
  err = TNGlueColorInit();

  // Initialize Cache
  CacheInit();

  // Open Database
  if (err == errNone)  err = OpenDatabase();
  if (err == errNone)  DatabaseSetCat(gPrefs.curCat);

  // Set Alarms
  if (err == errNone)  AlarmReset(DatabaseGetRefN(DB_MAIN));


  return (err);
}
Ejemplo n.º 6
0
/***************************************************************
                   RUND
 IN:
 N = upper bound (exclusive)
 OUT:
 a random number between 0 and N-1 inclusive: [0,N)
 PURPOSE:
 duh
****************************************************************/
Int rund(Int y)
{
  Int r;
  if (y <= 1) return 0;
  r = SysRandom(0);
  r = r % y; // 0 to y-1...
  return r;
}
Ejemplo n.º 7
0
/***************************************************************
                   RND
 IN:
 N = upper bound (inclusive)
 OUT:
 a random number between 1 and N inclusive: [1,N]
 PURPOSE:
 duh
****************************************************************/
Int rnd(Int y)
{
  Int r;
  if (y <= 1) return 1;
  r = SysRandom(0);
  r = (r % y) + 1; // 0 to y-1... add 1... 1 to y.
  return r;
}
Ejemplo n.º 8
0
Archivo: game.c Proyecto: docwhat/cwimp
int RollCube (void)
{
  static Boolean init = 0;

  if( init == 0 ) {
    sgenrand( SysRandom(0) );
    init++;
  }

  return ((genrand() %6) + 1);;
}
Ejemplo n.º 9
0
int getRandomK(void)
{
int r,k;

   r = SysRandom(0) % 100;
   if (r < 10)
      k = 0;           // 10% = .1
   else if (r < 18)
      k = 1;           // 8% = .08
   else if (r < 26)
      k = 2;           // 8% = .08
   else
      k = 3;           // 74% 

   return k;
}
Ejemplo n.º 10
0
int
Random (int max)
{
    int    v;

    v = game.seed;
    if (!v)
	v = 1;
    game.seed = SysRandom (v);
    v = game.seed;
    if (max)
    {
	if (v < 0)
	    v = -v;
        v %= max;
    }
    return v;
}
Ejemplo n.º 11
0
void drawSierpenski(int n)
{
   int x=0;
   int y=0;
   int tx[3],ty[3];
   int i,r;

   tx[1]=3;ty[1]=3; //init apex
   tx[2]=3;ty[2]=NY-3;
   tx[0]=NX-3;ty[0]=NY-3;

   x=tx[1]; y=ty[1];
   for(i=0;i<n;i++){
      WinDrawPixel(x,y);
      r=SysRandom(0) % 3;
      x=x+(tx[r]-x)/2;  // midpoint
      y=y+(ty[r]-y)/2;
   }
 }
Ejemplo n.º 12
0
static unsigned int
osip_fallback_random_number ()
#endif
{
  if (!random_seed_set)
    {
      unsigned int ticks;

#ifdef __PALMOS__
#	if __PALMOS__ < 0x06000000
      SysRandom ((Int32) TimGetTicks ());
#	else
      struct timeval tv;

      gettimeofday (&tv, NULL);
      srand (tv.tv_usec);
      ticks = tv.tv_sec + tv.tv_usec;
#	endif
#elif defined(WIN32)
      LARGE_INTEGER lCount;

      QueryPerformanceCounter (&lCount);
      ticks = lCount.LowPart + lCount.HighPart;
#elif defined(_WIN32_WCE)
      ticks = GetTickCount ();
#elif defined(__PSOS__)
#elif defined(__VXWORKS_OS__)
      struct timespec tp;

      clock_gettime (CLOCK_REALTIME, &tp);
      ticks = tp.tv_sec + tp.tv_nsec;
#else
      struct timeval tv;
      int fd;

      gettimeofday (&tv, NULL);
      ticks = tv.tv_sec + tv.tv_usec;
      fd = open ("/dev/urandom", O_RDONLY);
      if (fd > 0)
        {
          unsigned int r;
          int i;

          for (i = 0; i < 512; i++)
            {
              read (fd, &r, sizeof (r));
              ticks += r;
            }
          close (fd);
        }
#endif

#ifdef HAVE_LRAND48
      srand48 (ticks);
#else
      srand (ticks);
#endif
      random_seed_set = 1;
    }
#ifdef HAVE_LRAND48
  return lrand48 ();
#else
  return rand ();
#endif
}
Ejemplo n.º 13
0
static void
rando ()
{
    int ccount, cskip, tcount = TRACK_COUNT, tskip;
    int r, p, c, t;
    char* tmptracks[TRACK_COUNT];
    char* chars[CHAR_COUNT];

    // if we're not allowing rainbow road, decrement the tcount to 15 as
    // if the track doesn't exist
    if (!rainbow) tcount--;

    // make a temporary copy of the tracks array
    for (r = 0; r < TRACK_COUNT; r++) {
	tmptracks[r] = tracks[r];
    }

    // now select some random tracks
    for (r = 0; r < races; r++) {
	ccount = CHAR_COUNT;

	// make a temporary copy of the characters array
	for (c = 0; c < CHAR_COUNT; c++) {
	    chars[c] = characters[c];
	}

	for (p = 0; p < players; p++) {
	    // pick a random position
	    cskip = SysRandom(0) % ccount;

	    // now iterate over the list skipping already chosen characters
	    for (c = 0; c < cskip; c++) {
		while (chars[c] == 0) c++;
	    }

	    // skip any trailing used characters
	    while (chars[c] == 0) c++;

	    // decrement the character count for next time
	    ccount--;

	    if (p > 0) {
		StrCat(racestrs[r], chars[c]);
	    } else {
		StrCopy(racestrs[r], chars[c]);
	    }

	    if (p < players-1) {
		StrCat(racestrs[r], " ");
	    }

	    // mark the player as used
	    chars[c] = 0;
	}

	// pick a random position
	if (repeats) {
	    t = SysRandom(0) % tcount;

	} else {
	    tskip = SysRandom(0) % tcount;

	    // now iterate over the list skipping already chosen characters
	    for (t = 0; t < tskip; t++) {
		while (tmptracks[t] == 0) t++;
	    }

	    // skip any trailing used characters
	    while (tmptracks[t] == 0) t++;

	    // decrement the character count for next time
	    tcount--;
	}

	StrCat(racestrs[r], ": ");

	if (extra) {
	    StrCat(racestrs[r], SysRandom(0) % 100 > 50 ? "* " : "");
	}

	StrCat(racestrs[r], tmptracks[t]);

	// clear out this track if we're allowing no repeats
	if (!repeats) {
	    tmptracks[t] = 0;
	}
    }

    // update the list with the new choices
    LstSetListChoices(listPtr_races, &racestrs[0], races);

    // clear the list selection
    LstSetSelection(listPtr_races, -1);

    // and draw it
    LstDrawList(listPtr_races);
}
Ejemplo n.º 14
0
UInt32 tilf(UInt32 a, UInt32 b) {
  if (b < a)
    panic("b < a in tilf");
  return a + (SysRandom(0) % (b-a+1));
}