Difference between revisions of "Dev random"

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

Revision as of 23:05, 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;