Topic: Random
I am trying to use the pascal random() function and I get the error too many actual parameters.
N:=Random(9)+1;
My Visual Database → Script → Random
I am trying to use the pascal random() function and I get the error too many actual parameters.
N:=Random(9)+1;
The Random function generates random numbers. They can be floating point numbers in the range :
0 <= Number < 1.0
if you need random values from 0 to 99:
var
n: extended;
i: integer;
begin
n := Random*100; // with floating point
i := Trunc(Random*100); // int value
Hello, how to do it in MVDB example please? Function fx RandomRange is not implemented. I want to set via TextBoxses a min and max numeric value in script, Example: min. = 1 and max. = 45. Show 6 random numbers in the range 1 to 45, see below. Thanks in advance.
Example code : Generate random numbers in a very small range
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.
unit Unit1;
interface
uses
Math, // Unit containing the RandomRange command
SysUtils,
Forms, Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm} // Include form definitions
procedure TForm1.FormCreate(Sender: TObject);
var
i : Integer;
begin
// Show 5 random numbers in the range 652 to 656
for i := 1 to 5 do
ShowMessage('Random number : '+IntToStr(RandomRange(652, 656)));
end;
end.
Hi Carlo,
Is this the sort of thing you want? (see attached).
Just enter the number that you want to randomize up to (in your example, 45) and press 'Enter'.
Regards,
Derek.
Hello Derek,
Great job! Thanks.
Regards to,
Carlo
I will add function RandomRange to the next version.
Thanks Dmitry
Hello Derek,
Lotto app random45.zip not working after mvdb 5.3 b update? Can you check it pls. Next, I want to play with nrs between 5 and 40 X 12 gratings (squares). An example pls
now the function Random works differently
function Random ( LimitPlusOne : Integer ) : Integer;
Replace all lines like
form1.edit2.value := round((random) * (form1.edit1.value));
to
form1.edit2.value := random(Trunc(form1.edit1.value));
Thank you Dmitry
My Visual Database → Script → Random
Powered by PunBB, supported by Informer Technologies, Inc.
Theme Hydrogen by Kushi