Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Random Numbers
kvarnerexpress
post 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
Go to the top of the page
 
+Quote Post
bureX
post 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.
Go to the top of the page
 
+Quote Post
dul
post 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]
Go to the top of the page
 
+Quote Post
alphaobject
post 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;
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Most Efficient Code To Get Prime Numbers(7)
  2. Random Ventingness(5)
  3. Random Drug Searches In High School(12)
  4. Index In A Mysql Database(3)
  5. Lucky Pic Of My Dog(2)
  6. I Need Help(7)
  7. I Keep Seeing The Same Numbers Everywhere(11)
  8. Some Things I Hate(2)
  9. Strange Random '1' Appears(2)
  10. Php Random Titles(11)
  11. Memorise Large Numbers(7)
  12. What Are Imaginary Numbers(13)
  13. I Have Several Random Questions...(3)
  14. Random Bryce Renders(0)
  15. Bad Ram Can Cause Computer Failure To Start?(7)
  1. Sms With Text As Sender Address And Not Numbers!(1)
  2. What To Look For In A Pc...(7)
  3. Random Jokes...(0)
  4. Letters And Spellings Of Numbers(5)
  5. Hello(5)
  6. Do You Like George Bush(10)
  7. How To Make A Random 7 Number Code?(2)
  8. Is It Possible To Weigh Random Numbers?(6)
  9. Php - Randomize Web Title(5)
  10. How I Shall Scan Prime Numbers..(4)
  11. Gift To Wassie(6)
  12. What Would You Walk On Rather?(11)
  13. Rose Colored Window(2)
  14. Random Acts Of Violence(6)
  15. Random Post (request By Jlhaslip)(0)


 



- Lo-Fi Version Time is now: 16th May 2008 - 06:11 PM