Forum > General

design.rcbd/random

(1/1)

flori:
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:
I have some code to have a "random array".

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{  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/wiki/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:
Thank you:
The results>


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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;                               

Navigation

[0] Message Index

Go to full version