
-----------------------------------
lamnesia
Sun Jun 03, 2007 1:32 pm

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?

-----------------------------------
Cervantes
Sun Jun 03, 2007 1:38 pm

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
Sun Jun 03, 2007 1:40 pm

Re: Randomize Procedures
-----------------------------------
Thank you, but can you please post an example code?

thankx

-----------------------------------
lamnesia
Sun Jun 03, 2007 1:47 pm

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
Sun Jun 03, 2007 2:19 pm

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"Try This: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
Sun Jun 03, 2007 2:49 pm

RE:Randomize Procedures
-----------------------------------
Yeah, procedures are not integers. ;)

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
Sun Jun 03, 2007 3:11 pm

RE:Randomize Procedures
-----------------------------------
thank you guys so much XD it works perfectly. Now i just needa make sure that the questions dont repeat themselves
