Topic: Random

I am trying to use the pascal random() function and I get the error too many actual parameters.

N:=Random(9)+1;

Re: Random

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
Dmitry.

Re: Random

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.

Re: Random

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.

Post's attachments

Attachment icon random45.zip 337.04 kb, 366 downloads since 2019-03-11 

Re: Random

Hello Derek,

Great job! Thanks.

Regards to,

Carlo

Re: Random

I will add function RandomRange to the next version.

Dmitry.

Re: Random

Thanks Dmitry

Re: Random

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

Post's attachments

Attachment icon Multi-Random Lotto-BE.zip 364.08 kb, 359 downloads since 2019-03-21 

Re: Random

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));
Dmitry.

Re: Random

Thank you Dmitry