* ==========================================================================
* Demo: Random Number
* Caution: no error check for the sake of briefness and understandability
* Tips:
* Random number generation is very important for many encryption algorithms. Our Dongle 
* has the function of random number generation.  First of all, the length of the random 
* number has to be set through DIC_Set (maximum length of 16 bytes, set with RANDOM_SIZE 
* macro), and then call the command RANDOM to get the random number.  The random number is
* stored in cmddata. 
* 
* you can call this function many times and connect them together if you want more longer 
* random number.
* ==========================================================================
#include "Dic32_Vfp.h"
clear 
DECLARE integer   DIC_Find IN DIC32U.dll
DECLARE integer   DIC_Open IN DIC32U.dll integer hic, string @  reader_name
DECLARE integer   DIC_Close  IN DIC32U.dll  integer   hic
DECLARE integer   DIC_Command  IN DIC32U.dll  integer  hic, integer cmd, string @  cmddata
DECLARE integer   DIC_Get  IN DIC32U.dll  string @  xdata, integer  p1, integer   p2, string @  buffer
DECLARE integer   DIC_Set  IN DIC32U.dll  string @  xdata, integer  p1, integer  p2, integer   p3, string @  buffer

store 0 to  errcode		   && error code
store 0 to  num		   && number of founded card reader(s)
store 0 to  hic		   && handle of ROCKEY device
store 0 to  i
cmddata=space(256)
                                                                                                   
dimension temp[16]



	num = DIC_Find()
	for i=0 to num-1
		hic = DIC_Open(i, NULL)
		if (hic >= 0) 
		  exit  	&& Stop searching once one is found.
  	  endif
	endfor
	if (i == num) 
	     return
    endif


	DIC_Set(@cmddata, RANDOM_SIZE, BY_VALUE, 16, NULL) 	&& Set the random number length
	errcode = DIC_Command(hic,RANDOM, @cmddata) 	&& Get the random number
	
	for i= 1 to  16 
	   temp[i]=DIC_Get(@cmddata,i-1,1,NULL)
    endfor
    ?temp[1],temp[2],temp[3],temp[4],temp[5],temp[6],temp[7],temp[8]
    ?temp[9],temp[10],temp[11],temp[12],temp[13],temp[14],temp[15],temp[16]
	
	errcode = DIC_Close(hic)  
clear dlls
return 	