|
|
|
|
![]() ![]() |
Oct 27 2005, 09:01 PM
Post
#1
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 407 Joined: 13-December 04 Member No.: 2,696 |
I'm trying to do random numbers...
I use Randomize() ; and then run Random() ; several times in a loop the 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: CODE function RandomFunction(): Integer; var x: Integer begin 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... grrrrr i'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 |
|
|
|
Oct 27 2005, 09:24 PM
Post
#2
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 318 Joined: 5-January 05 Member No.: 3,136 |
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.
|
|
|
|
Oct 27 2005, 11:26 PM
Post
#3
|
|
|
Member [Level 1] ![]() ![]() ![]() ![]() Group: Members Posts: 73 Joined: 21-September 05 Member No.: 12,113 |
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)); [/quote] |
|
|
|
Jan 15 2006, 08:02 AM
Post
#4
|
|
|
Newbie ![]() Group: Members Posts: 3 Joined: 15-January 06 Member No.: 17,147 |
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; |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 16th May 2008 - 06:11 PM |