design.rcbd/random lazarus / 62-General ---------------------------------------------------------------------- flori · 2021-05-05 15:44 Hi everyone! I would like to generate randomized block design in lazarus. Does anyone know how to mix(randomizes) the numbers within the block? For example: Treatments: 10 Replication: 2 ------------------------- Results: "1"  "2"  "5"  "10" "3"  "4"  "6"  "8"  "9"  "7" "6"  "4"  "3"  "7"  "10" "9"  "5"  "1"  "2"  "8" rows= replication,  col= trt unfortunately, Rstat software sometimes mixes badly (design.rcbd). I attached my demo. Thank you ---------------------------------------------------------------------- Bart · 2021-05-05 15:49 I have some code to have a "random array". Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {  Returns an array of aSize random integers without duplicates ranging from  aFrom (inclusive) to aTo (exclusive).  - aFrom and aTo must be positive integers  - aTo must be > aFrom  - aSize must be <= aTo - aFrom  - if either of these conditions is not met, an empty array will be returned.}function RandomArray(aFrom, aTo, aSize: Integer): TIntegerDynArray; overload;var  i, j, temp, Range: Integer;begin  Range := (aTo - aFrom);  if (aFrom < 0) or (aFrom >= aTo) or (aSize > Range) then    Exit(nil);  SetLength(Result, Range);  for i := Low(Result) to High(Result) do Result[i] := aFrom + i;  // Use te Sattolo algorithm to shuffle the array  // https://en.wikipedia.org/wi ki/Fisher%E2%80%93Yates_shuffle#Sattolo.27s_algorithm  i := Length(Result);  while i > 0 do  begin    Dec(i);    j := Random(i);  temp := Result[i];    Result[i] := Result[j];    Result[j] := temp;  end;  if (aSize <> Range) then    SetLength(Result, aSize);end; function RandomArray(aFrom, aTo: Integer): TIntegerDynArray; inline; overload;begin  Result := RandomArray(aFrom, aTo, (aTo - aFrom));end; function RandomArray(Range: Integer): TIntegerDynArray; inline; overload;begin  Result := RandomArray(0, Range, Range);end; As you can see it uses Fisher Yates Shuffle algorithm. Bart ---------------------------------------------------------------------- flori · 2021-05-05 16:57 Thank you: The results> Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i begin    randomize;    n:=0;    write('rep: ');  readln(n);        //      for  d:=1 to n do    begin       a:=a.Create(1,2,3,4,5,6,7,8,9,10);        i := length(a);       while i > 0 do        begin      dec(i);      j :=randomrange(Low(a),i);      t:=a[i];a[i]:=a[j];a[j]:=t;      write(a[i],' ');      end;       writeln('');       writeln('---------------');       end;