Пример #1
0
static ssize_t devurand_read(FAR struct file *filep, FAR char *buffer,
                             size_t len)
{
#ifdef CONFIG_DEV_URANDOM_RANDOM_POOL
  if (len)
    {
      getrandom(buffer, len);
    }
#else
  size_t n;
  uint32_t rnd;

  n = len;

  /* Align buffer pointer to 4-byte boundry */

  if (((uintptr_t)buffer & 0x03) != 0)
    {
      /* Generate a pseudo random number */

      rnd = PRNG();

      while (((uintptr_t)buffer & 0x03) != 0)
        {
          if (n <= 0)
            {
              return len;
            }

          *buffer++ = rnd & 0xff;
          rnd >>= 8;
          --n;
        }
    }
Пример #2
0
Файл: Sample.c Проект: 5rm/DS203
int main(void)
{ 
  NVIC_SetVectorTable(NVIC_VectTab_FLASH, (u32)&_vectors);
  __USB_Init();
  //__Clear_Screen(0x0000);
  // display 400x240

  for (int x=0; x<400; x++)
    for (int y=0; y<240-16; y++)
    {
      u32 dx = (x-200);
      u32 dy = (y-120);
      dx *= dx;
      dy *= dy;
      u32 dl = dx+dy;

      __Point_SCR(x, y);
      __LCD_SetPixl((uc16)(dl>>3) & 0x001f);
    }

  __Display_Str(20, 200, 0xffff, 0, "Hello DS203 Test... ");

  int x[3] = {20, 380, 220};
  int y[3] = {20, 40, 220};

  int curx = x[0];
  int cury = y[0];
  while ( !(GetKeys() & KEY2_STATUS) ) 
  {
    int c = PRNG();
    int r = c%3;
    curx = (curx+x[r]) >> 1;
    cury = (cury+y[r]) >> 1;

    __Point_SCR(curx, cury);
    __LCD_SetPixl(c<<1); // len do 32k
  }
	Reboot();
  return 0;
}
Пример #3
0
void Random<T_PRNG>::Init(const uint64_t& seed)
{
    ResetState(PRNG(static_cast<typename PRNG::result_type>(seed)));
}