Difference between revisions of "Dev random"

From Free Pascal wiki
Jump to navigationJump to search
 
Line 9: Line 9:
  
 
= Coding =
 
= Coding =
 +
In order to make Free Pascal work with /dev/random and /dev/random we shell write the following code:
 +
 +
procedure RandomSeed;
 +
var
 +
  f : file of integer;
 +
  i : integer;
 +
 +
begin
 +
  i := 0;
 +
  filemode:=0;
 +
  AssignFile(f, '/dev/urandom');
 +
  reset(f,1);
 +
  read (f,i);
 +
  CloseFile (f);
 +
  RandSeed := i;
 +
end;

Revision as of 22:04, 21 July 2005

Summery

/dev/random and /dev/urandom are two Unix and *nix based devices that allow receives memory, disc, network dumps from the kernel. This allow us to use “random�? like seed for preforming “random' tasks. with the “random�? function.

The difference between /dev/random and /dev/urandom is the “blocking�? and “non blocking�? issues.

While /dev/random will give us random seeds, it will wait until it will have something to give us, before return with the seed.

/dev/urandom does not stop us from when we do not have new seed from dump, and will return also clock cycles, that are less random, but that way we will not need to wait until any type of activity will occure.

Coding

In order to make Free Pascal work with /dev/random and /dev/random we shell write the following code:

procedure RandomSeed;
var
 f : file of integer;
 i : integer;

begin
 i := 0;
 filemode:=0;
 AssignFile(f, '/dev/urandom'); 
 reset(f,1);
 read (f,i);
 CloseFile (f);
 RandSeed := i;
end;