Random !!!

Post your requests and ideas on the future development of mikroPascal for AVR.
Post Reply
Author
Message
mbruck
Posts: 51
Joined: 19 Apr 2006 21:55

Random !!!

#1 Post by mbruck » 17 Sep 2006 00:04

Random and Randomize !!!

vanja
mikroElektronika team
Posts: 253
Joined: 27 Jan 2005 15:13
Contact:

#2 Post by vanja » 18 Sep 2006 07:49

Here is a library:

Code: Select all

unit random;


var  randx : longint;
     randf : byte;

//-------------- Random number seed
procedure srand(x : longint);
  begin
	  randx := x;
	  randf := 1;
  end;

//-------------- Random number generator
function rand : word;
  begin
		if(randf = 0) then
			srand(1);
	  randx  := (((randx * 1103515245) + 12345) shr 16) and 0x077777;
	  result := word(randx);
  end;
end.
And here is a main program:

Code: Select all

program random_number_test;

uses random;

begin
  ddrb := $ff;
  srand(100);
  while true do
    begin
      portb:= rand;
      delay_ms(100);
    end;
end.
It's tested and it works.

mbruck
Posts: 51
Joined: 19 Apr 2006 21:55

Tnx..

#3 Post by mbruck » 18 Sep 2006 22:10

Tnx !

Post Reply

Return to “mikroPascal for AVR Wish List”