Function RandomKey() Foundation

Calculates a random character string

Syntax
RandomKey( <nLen> ) --> cKey
Parameters
<nLen>
The parameter <nLen> determines the length of the character string returned.
Return

The function returns a character string of the length that is determined by the parameter. This character string may include all characters ranging from Chr(0) to Chr(255).

Description

The function RandomKey() produces a character string of random values. The length is determined by the parameter nLen. If available, the function hereby uses the Cryptoprovider of the operating system which delivers the maximum entropy available.

A cryptoprovider is available on Windows XP / Windows 2003 and higher.

RandomKey() follows strict cryptographic standards. However, it is slower than the function RandomInt() .

Examples
Fill a CRT with random RGB values per pixel
 // This sample requires the program to be linked as GUI application. 
 // (linker switch /PM:PM or GUI=yes in the project file). 
PROCEDURE Main() 
   LOCAL oBmp, nXS, nYS 
   LOCAL aSize, cBuff 
   LOCAL cHeader 

   CLS 
   aSize := SetAppWindow():currentSize() 
   nXS := Int( aSize[1] ) 
   nYS := Int( aSize[2] ) 

   // Create Bitmap 24 Bit color depth 
   oBmp := XbpBitmap():new():create() 
   oBmp:make(nXS, nYS, , 24) 

   // Cut Bitmap Header 
   cHeader := SubStr(oBmp:setBuffer(), 1, oBmp:bufferOffset ) 

   // Append the header with 3 Byte per pixel. 
   // This is a random RGB value for each pixel 
   cBuff := cHeader + RandomKey( nXS*nYS*3 ) 

   // Set the buffer and paint 
   oBmp:setBuffer( cBuff ) 
   oBmp:draw(, {0,0,nXS,nYS}) 

   oBmp:destroy() 
   wait 
RETURN 
Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.