Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

question

Status
Not open for further replies.

slasticar

Technical User
Nov 1, 2006
12
BA
I have one question, first of akll I want to thanks to everyone who gives me advice for director.
Qustion is:
I hava database of 40 questions with a,b,c,d answer. How can I make randomize questions of 10 questions.
Thank you.
 
Code:
on generate10randomNumFrom40
  list40 = []
  repeat with i = 1 to 40
    list40.append(i)
  end repeat
  n = 40
  repeat while n > 1
    m = random(n)
    tN = list40[n]
    tM = list40[m]
    list40[n] = tM
    list40[m] = tN
    n = n - 1
  end repeat
  list10 = []
  repeat with i = 1 to 10
    list10[i] = list40[i]
  end repeat
  return list10
end generate10randomNumFrom40

put generate10randomNumFrom40()
-- [29, 9, 32, 2, 1, 5, 23, 31, 21, 35]

put generate10randomNumFrom40()
-- [24, 28, 40, 21, 35, 20, 30, 11, 33, 18]

Kenneth Kawamoto
 
Sorry because I am boring but I am beginner, can you tell me where I need to put this code and how to integrate this code with my data base of question .
 
The code above is to obtain 10 random numbers from 1 - 40. I don't know how you structure your database, but say you have 40 questions in a List; you can use the 10 random numbers as index to pick up 10 random questions.

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top