Example #1
0
//========================================
//test_fun3 功能是取16字节随机数
//
//========================================
void test_fun3(unsigned char xdata *TxComm) // get random
{
 GetRandomData( TxComm + 1, 16 );

 TxComm[0] = 16 ;

}
Example #2
0
static void DemoRandomGraph(void) {
  PARAM Param;
  int tDiff, t0;
  GUI_RECT Rect = {19, (LCD_YSIZE - 20) - YSIZE, (LCD_XSIZE - 2), (LCD_YSIZE - 21)};
  GUI_HMEM hMem = GUI_ALLOC_Alloc((LCD_XSIZE - 20) * sizeof(I16));
  GUI_SetColor(GUI_WHITE);
  GUI_SetBkColor(GUI_RED);
  GUI_ClearRect(0, 0, LCD_XSIZE, 60);
  GUI_SetFont(&GUI_FontComic18B_1);
  GUI_DispStringAt("Random graph", 10, 20);
  Param.aY = GUI_ALLOC_h2p(hMem);
  GUI_SetFont(&GUI_Font6x8);
  t0 = GUI_GetTime();
  while((tDiff = (GUI_GetTime() - t0)) < 10000) {
    int t1, tDiff2;
    GetRandomData(Param.aY, tDiff, (LCD_XSIZE - 20));
    t1 = GUI_GetTime();
    GUI_MEMDEV_Draw(&Rect, Draw, &Param, 0, 0);
    tDiff2 = GUI_GetTime() - t1;
    if (tDiff2 < 100) {
      GUI_Delay(100 - tDiff2);
    }
  }
  GUI_ALLOC_Free(hMem);
}
Example #3
0
// generate random numbers from a buffer filled in by GetRandomData()
unsigned int PWSrand::RandUInt()
{
  // we don't want to keep filling the random buffer for each number we
  // want, so fill the buffer with random data and use it up

  if (ibRandomData > (SHA256::HASHLEN - sizeof(uint32))) {
    // no data left, refill the buffer
    GetRandomData(rgbRandomData, SHA256::HASHLEN);
    ibRandomData = 0;
  }

  const unsigned int u =
    *(reinterpret_cast<uint32 *>(rgbRandomData + ibRandomData));
  ibRandomData += sizeof(uint32);
  return u;
}
Example #4
0
//-----------------------------------------------------------------------------
// Program entry-point function
//-----------------------------------------------------------------------------
int main (int argc, char *argv[])
{
	int						ddcError = 0;
	DDCFileHandle			file = 0;
	DDCChannelGroupHandle	group;
	DDCChannelHandle		channels[2];
	double					channel1Data[NUM_DATA_PTS], channel2Data[NUM_DATA_PTS];
	
	// If file exists, delete it.
	remove (FILE_PATH);

	printf ("Generating data file...\n");
	
	// Create file and add channel group and channels.
	ddcChk (DDC_CreateFile (FILE_PATH, "TDM", FILE_NAME, FILE_DESC, "", "", &file));
	ddcChk (DDC_AddChannelGroup (file, GROUP_NAME, GROUP_DESC, &group));
	ddcChk (DDC_AddChannel (group, DDC_Double, CHANNEL1_NAME, 
		CHANNEL1_DESC, CHANNEL1_UNITS, &channels[0]));
	ddcChk (DDC_AddChannel (group, DDC_Double, CHANNEL2_NAME, 
		CHANNEL2_DESC, CHANNEL2_UNITS, &channels[1]));
		
	GetSineData (NUM_DATA_PTS, channel1Data);
	GetRandomData (NUM_DATA_PTS, channel2Data);

	// Write the data in the channels
	ddcChk (DDC_SetDataValues (channels[0], channel1Data, NUM_DATA_PTS));
	ddcChk (DDC_SetDataValues (channels[1], channel2Data, NUM_DATA_PTS));
		
	// Save the file
	ddcChk (DDC_SaveFile (file));
	
Error:
	// Close the file and report any errors
	if (file)
		DDC_CloseFile (file);
	if (ddcError < 0)
		printf ("\nError: %s\n", DDC_GetLibraryErrorDescription(ddcError));
	else
		printf ("\nNo errors.\n");
	printf("End of program, press Enter key to quit\n");
	getchar();
	return 0;
}