From Clomosy Docs

No edit summary
No edit summary
Line 12: Line 12:


'''Example:'''<br>
'''Example:'''<br>
'''var'''
:'''Base Syntax'''
   MyForm:TclForm;
   var
  btnShow : TclButton;<br>
  MyForm:TclForm;
'''procedure randomNumber'''
  btnShow : TclButton;
  var number:Float;
 
  procedure randomNumber
  var number:Float;
  begin
    number := '''Random'''() * 100;
    ShowMessage(IntToStr(number));
  end;
 
   begin
   begin
    number := '''Random() * 100;'''
  MyForm := TclForm.Create(Self);
    ShowMessage(IntToStr(number));
 
   end;<br>
  btnShow:= MyForm.AddNewButton(MyForm,'btnShow','Random');
'''begin'''
  btnShow.TextSettings.Font.Size:=50;
   MyForm := TclForm.Create(Self);<br>
  btnShow.Align := alCenter;
   btnShow:= MyForm.AddNewButton(MyForm,'btnShow','Random');
  btnShow.Height := 50;
  btnShow.TextSettings.Font.Size:=50;
  btnShow.Width := 100;
  btnShow.Align := alCenter;
  MyForm.AddNewEvent(btnShow,tbeOnClick,'randomNumber');
  btnShow.Height := 50;
 
  btnShow.Width := 100;
  MyForm.Run;
  MyForm.AddNewEvent(btnShow,tbeOnClick,'randomNumber');<br>
   end;
   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;
  }

Revision as of 13:26, 13 February 2024

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;
 }