|
|
| Line 1: |
Line 1: |
| This function is a custom function used on the Clomosy platform. It is employed to generate a random number between two numerical values. The randomly generated number within the function is inclusive of the first parameter but exclusive of the last parameter.
| | <div class="alert alert-ligth border border-3 border-primary-subtle rounded-5 p-4 shadow-sm" role="alert"> |
| | clMath.GenerateRandom(value1,value2:Integer):Integer |
| | </div> |
|
| |
|
| clMath.GenerateRandom(value1,value2:Integer):Integer
| | This function is a custom function used on the Clomosy platform. It is employed to generate a random number between two numerical values. The randomly generated number within the function is inclusive of the first parameter but exclusive of the last parameter.<br> |
|
| |
|
| '''Example:'''<br>
| | |
| In the example, when the program is executed, a random number between 10 and 20 will be generated. To guess this number, a numeric input must be entered into the edit component. If the number is guessed correctly, it will display a message "correct guess," and if guessed incorrectly, it will display "wrong guess," revealing the correct number, and the process will end. | | <b>Example</b><br> |
| :'''Base Syntax'''
| | In the example, when the program is executed, a random number between 10 and 20 will be generated.<br> |
| var
| | <b>TRObject Syntax</b><br> |
| mainForm:TclForm;
| | <pre> |
| guessEdt : TclEdit;
| | var |
| guessBtn : TclButton;
| | NumberOfPredictions : Integer; |
| NumberOfPredictions : Integer;
| |
|
| |
| procedure guessClick;
| |
| begin
| |
| if guessEdt.Text = <nowiki>''</nowiki> then
| |
| begin
| |
| ShowMessage('Enter number!')
| |
| end else
| |
| begin
| |
| if StrToInt(guessEdt.Text) = NumberOfPredictions then
| |
| begin
| |
| ShowMessage('The number is correct.');
| |
| end
| |
| else
| |
| ShowMessage('The number is wrong. Correct Number: '+IntToStr(NumberOfPredictions));
| |
| end
| |
| end;
| |
|
| |
| begin | |
| mainForm := TclForm.Create(Self);
| |
| NumberOfPredictions := clMath.GenerateRandom(10,20);
| |
|
| |
| guessEdt:= mainForm.AddNewEdit(mainForm,'guessEdt','Enter the number you guessed...');
| |
| guessEdt.TextSettings.Font.Size:=70;
| |
| guessEdt.Align := alTop;
| |
| guessEdt.Margins.Top:= 10;
| |
| guessEdt.Height := 50;
| |
| guessEdt.Width := 150;
| |
|
| |
| guessBtn:= mainForm.AddNewButton(mainForm,'guessBtn','Guess');
| |
| guessBtn.TextSettings.Font.Size:=50;
| |
| guessBtn.Align := alCenter;
| |
| guessBtn.Height := 50;
| |
| guessBtn.Width := 100;
| |
| mainForm.AddNewEvent(guessBtn,tbeOnClick,'guessClick');
| |
|
| |
| mainForm.Run;
| |
| end;
| |
|
| |
|
| | { |
| | NumberOfPredictions = clMath.GenerateRandom(10,20); |
| | ShowMessage('The generated number: '+IntToStr(NumberOfPredictions)); |
| | } |
| | </pre> |
| | <b>Base Syntax</b><br> |
| | <pre> |
| | var |
| | NumberOfPredictions : Integer; |
|
| |
|
| :'''TRObject Syntax'''
| | begin |
| var | | NumberOfPredictions := clMath.GenerateRandom(10,20); |
| mainForm:TclForm;
| | ShowMessage('The generated number: '+IntToStr(NumberOfPredictions)); |
| guessEdt : TclEdit;
| | end; |
| guessBtn : TclButton;
| | </pre> |
| NumberOfPredictions : Integer;
| | |
|
| | <b>Output:</b><br> |
| void guessClick;
| | <div class="alert alert-success" role="alert" data-bs-theme="light"> |
| {
| | The generated number: 10 |
| if(guessEdt.Text == <nowiki>''</nowiki>)
| | </div> |
| {
| | |
| ShowMessage('Enter number!')
| | <h2> See Also </h2> |
| }else{
| | * [[ClMath | ClMath]] |
| if (StrToInt(guessEdt.Text) == NumberOfPredictions){
| |
| ShowMessage('The number is correct.');
| |
| }else{
| |
| ShowMessage('The number is wrong. Correct Number: '+IntToStr(NumberOfPredictions));
| |
| }
| |
| }
| |
| }
| |
| {
| |
| mainForm = TclForm.Create(Self);
| |
| NumberOfPredictions = clMath.GenerateRandom(10,20);
| |
|
| |
| guessEdt= mainForm.AddNewEdit(mainForm,'guessEdt','Enter the number you guessed...');
| |
| guessEdt.TextSettings.Font.Size=70;
| |
| guessEdt.Align = alTop;
| |
| guessEdt.Margins.Top= 10;
| |
| guessEdt.Height = 50;
| |
| guessEdt.Width = 150;
| |
|
| |
| guessBtn= mainForm.AddNewButton(mainForm,'guessBtn','Guess');
| |
| guessBtn.TextSettings.Font.Size=50;
| |
| guessBtn.Align = alCenter;
| |
| guessBtn.Height = 50;
| |
| guessBtn.Width = 100;
| |
| mainForm.AddNewEvent(guessBtn,tbeOnClick,'guessClick');
| |
|
| |
| mainForm.Run;
| |
| }
| |
clMath.GenerateRandom(value1,value2:Integer):Integer
This function is a custom function used on the Clomosy platform. It is employed to generate a random number between two numerical values. The randomly generated number within the function is inclusive of the first parameter but exclusive of the last parameter.
Example
In the example, when the program is executed, a random number between 10 and 20 will be generated.
TRObject Syntax
var
NumberOfPredictions : Integer;
{
NumberOfPredictions = clMath.GenerateRandom(10,20);
ShowMessage('The generated number: '+IntToStr(NumberOfPredictions));
}
Base Syntax
var
NumberOfPredictions : Integer;
begin
NumberOfPredictions := clMath.GenerateRandom(10,20);
ShowMessage('The generated number: '+IntToStr(NumberOfPredictions));
end;
Output:
See Also