KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Method to Generate a Random RGB Hex Color
PRODUCT: 4D | VERSION: 14.3 | PLATFORM: Mac & Win
Published On: March 5, 2015

Below is a method to generate a random RGB hex color:

// Method: RandomRGBColor
// Description: Returns a random RGB Color Hex Value
// $0: A valid value from 0x00000000 (0) to 0X00FFFFFF (16777215)

C_LONGINT($0)
C_INTEGER($red;$green;$blue)
$red:=Random%255
$green:=Random%255
$blue:=Random%255
$0:=($red<<16)+($green<<8)+$blue


Below is an example of using the method. The RandomRGBColor method is placed in the button to change the Rectangle Object's (named "Rectangle") color to a random color.

The Method in the button is:
OBJECT SET RGB COLORS(*;"Rectangle";RandomRGBColor ;RandomRGBColor )