Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Randomize Procedures
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
lamnesia




PostPosted: Sun Jun 03, 2007 1:32 pm   Post subject: Randomize Procedures

Is there a way for me to randomize a set of procedures? Say 1 procedure is asking 1 question and it also includes the correct answer, but there are 40 procedures and i wanna take out 20 random ones. Can anyone please help me?
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Sun Jun 03, 2007 1:38 pm   Post subject: RE:Randomize Procedures

Sure, you can make an array of procedures and then pick a random element. Or you could have all your questions and answers stored in a file, then read the data into an array so that you've got one element for each question, then pick a random element. I think the second approach is better, because it involves a more general solution. You don't have to write a new procedure for each question. Your code will stay small, even if you have thousands of questions.
lamnesia




PostPosted: Sun Jun 03, 2007 1:40 pm   Post subject: Re: Randomize Procedures

Thank you, but can you please post an example code?

thankx
lamnesia




PostPosted: Sun Jun 03, 2007 1:47 pm   Post subject: Re: Randomize Procedures

oh and also i tried to make an array of procedures

like
procedure question1
bl bla bla
end question1
procedure question2
bla bla bla
end question2

var randomquestion :array 1..2 of int
var num : int
randomquestion (1) := question1
randomquestion (2) := question2

loop
num := Rand.Int (1,2)
put randquestion (num)
end loop

but it gave me an error:

"Assigned"
DIIST




PostPosted: Sun Jun 03, 2007 2:19 pm   Post subject: Re: Randomize Procedures

lamnesia @ Sun Jun 03, 2007 1:47 pm wrote:
oh and also i tried to make an array of procedures

like
procedure question1
bl bla bla
end question1
procedure question2
bla bla bla
end question2

var randomquestion :array 1..2 of int
var num : int
randomquestion (1) := question1
randomquestion (2) := question2

loop
num := Rand.Int (1,2)
put randquestion (num)
end loop

but it gave me an error:

"Assigned"
Try This:
Turing:
proc p1
    put "Procedure 1"
end p1

proc p2
    put "Procedure 2"
end p2

proc p3
    put "Procedure 3"
end p3


var p : array 1 .. 3 of procedure blah ()


p (1) := p1
p (2) := p2
p (3) := p3


p (Rand.Int (1, 3))
Cervantes




PostPosted: Sun Jun 03, 2007 2:49 pm   Post subject: RE:Randomize Procedures

Yeah, procedures are not integers. Wink

The thing is that a procedure that accepts no arguments is different from a procedure that accepts one argument, and that is also different from a procedure that accepts two arguments, etc. Probably the way to go with this approach is to make all your procedures accept no arguments.
lamnesia




PostPosted: Sun Jun 03, 2007 3:11 pm   Post subject: RE:Randomize Procedures

thank you guys so much XD it works perfectly. Now i just needa make sure that the questions dont repeat themselves
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: