|
|
| (3 intermediate revisions by 2 users not shown) |
| 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
| |
| mainForm:TclForm;
| |
| guessEdt : TclEdit;
| |
| guessBtn : TclButton;
| |
| 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;
| |
|
| |
|
| | <pre> |
| | var |
| | NumberOfPredictions : Integer; |
|
| |
|
| :'''TRObject Syntax'''
| | { |
| var | | NumberOfPredictions = clMath.GenerateRandom(10,20); |
| mainForm:TclForm;
| | ShowMessage('The generated number: '+IntToStr(NumberOfPredictions)); |
| guessEdt : TclEdit;
| | } |
| 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){
| | {{#seo:|title=GenerateRandom in Clomosy - Clomosy Docs}} |
| ShowMessage('The number is correct.');
| | {{#seo:|description=Learn to generate random numbers using the clMath.GenerateRandom function in Clomosy.}} |
| }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.
var
NumberOfPredictions : Integer;
{
NumberOfPredictions = clMath.GenerateRandom(10,20);
ShowMessage('The generated number: '+IntToStr(NumberOfPredictions));
}
Output:
See Also