From Clomosy Docs

Revision as of 13:26, 13 February 2024 by ClomosyManager (talk | contribs)

function Random():Extended;

The random function generates random numbers. These can be floating-point numbers in the following range:
0 <= Number < 1.0

It can be used by calling as follows. This call will generate a decimal random number value between 0 and 1.

x := Random();

If you want to get an integer value, define it as follows. Here it will return a random value between 0 and 100. After that, you can get values ​​as you want.

x := Random() * 100;

Example:

Base Syntax
 var
  MyForm:TclForm;
  btnShow : TclButton;
 
 procedure randomNumber
  var number:Float;
  begin
    number := Random() * 100; 
    ShowMessage(IntToStr(number));
  end;
 
 begin
  MyForm := TclForm.Create(Self);
 
  btnShow:= MyForm.AddNewButton(MyForm,'btnShow','Random');
  btnShow.TextSettings.Font.Size:=50;
  btnShow.Align := alCenter;
  btnShow.Height := 50;
  btnShow.Width := 100;
  MyForm.AddNewEvent(btnShow,tbeOnClick,'randomNumber');
 
  MyForm.Run;
 end;
TRObject Syntax
 var
  MyForm:TclForm;
  btnShow : TclButton;
 
 void randomNumber
  var number:Float;
  {
    number = Random() * 100; 
    ShowMessage(IntToStr(number));
  }
 
 {
  MyForm = TclForm.Create(Self);
 
  btnShow = MyForm.AddNewButton(MyForm,'btnShow','Random');
  btnShow.TextSettings.Font.Size=50;
  btnShow.Align = alCenter;
  btnShow.Height = 50;
  btnShow.Width = 100;
  MyForm.AddNewEvent(btnShow,tbeOnClick,'randomNumber');
 
  MyForm.Run;
 }