kvarnerexpress 0 Report post Posted October 27, 2005 I'm trying to do random numbers...I use Randomize() ;and then run Random() ; several times in a loopthe only trouble is that each time I run the program the output is the same each pass through the loop..ie... it's supposed to output a random number on each of three passes through the loop...it's actuall..Code: function RandomFunction(): Integer;var x: Integerbegin x := Random(12) + 1; Result := x;end;procedure Main;var i: Integer;begin Randomize(); for i := 1 to 3 do showmessage(IntToStr(CallMyFunction()));end; so... it'll output 4 three times, and then i'll run it again and it'll output 7 three times... grrrrri'm pretty sure i remember something about the Randomize() function being linked to the system clock, but I don't remember how... or necessarily all the implications of it... though I do remember that I'm not supposed to call it in the loop...thanks,kvarnerexpress Share this post Link to post Share on other sites
bureX 0 Report post Posted October 27, 2005 Well, the only errors that I found in your code were a missing semicolon... I replaced "CallMyFunction()" with "RandomFunction()", added the missing semicolon and compiled the program... Everything works! I don't really see what could be wrong with your code... Try doing some debugging and watch the "X" variable change during the execution of the program. Share this post Link to post Share on other sites
dul 0 Report post Posted October 27, 2005 Of course, that is doesh't work. You didn't send any random numbers. Because you calling unidentified function which hash't got in your source code or calling wrong function. try this one. It will work [quote= showmessage(IntToStr(RandomFunction)); Share this post Link to post Share on other sites
alphaobject 0 Report post Posted January 15, 2006 Can try this version : function RandomFunction: Integer;var x: Integer;begin Randomize; x := Random(12) + 1; Result := x;end;procedure Main;var i: Integer;begin for i := 1 to 3 do showmessage(IntToStr(CallMyFunction()));end; Share this post Link to post Share on other sites