一个很简单的例子,打印256个字节
#include <Uefi.h> #include <Library/UefiLib.h> #include <Library/ShellCEntryLib.h> extern EFI_BOOT_SERVICES *gBS; extern EFI_SYSTEM_TABLE *gST; extern EFI_RUNTIME_SERVICES *gRT; static UINT32 next = 1; /** Expands to an integer constant expression that is the maximum value returned by the rand function. **/ #define RAND_MAX 0x7fffffff /** Compute a pseudo-random number. * * Compute x = (7^5 * x) mod (2^31 - 1) * without overflowing 31 bits: * (2^31 - 1) = 127773 * (7^5) + 2836 * From "Random number generators: good ones are hard to find", * Park and Miller, Communications of the ACM, vol. 31, no. 10, * October 1988, p. 1195. **/ int rand() { INT32 hi, lo, x; /* Can't be initialized with 0, so use another value. */ if (next == 0) next = 123459876; hi = next / 127773; lo = next % 127773; x = 16807 * lo - 2836 * hi; if (x < 0) x += 0x7fffffff; return ((next = x) % ((UINT32)RAND_MAX + 1)); } void srand(unsigned int seed) { next = (UINT32)seed; } int EFIAPI main ( IN int Argc, IN CHAR16 **Argv ) { UINT32 Buffer[256]; UINT32 i; UINT32 j; srand(0); for (i=0;i<256;i++) { Buffer[i]=(UINT8)(rand()%256); } Print(L" \\|"); for (i=0;i<16;i++) { Print(L" %2X|",i); } Print(L"\n"); for (j=0;j<16;j++) { Print(L"%2X| ",j); for (i=0;i<16;i++) { Print(L"%2X ",Buffer[i*16+j]); } Print(L"\n"); } return EFI_SUCCESS; } 运行结果:完整的程序