Ravi,

If it weren't for a bug in Director, you could do it in this simple manner:

on GetRandomAnswerList
  set tText = member("Answers").text
  set tAnswerList = []
  repeat while the number of lines in tText > 0
    set tRand = random(the number of lines in tText)
    tAnswerList.add(tText.line[tRand])
    delete line tRand of tText
  end repeat
  return tAnswerList
end

Unfortunately, even an EMPTY string counts as 1 line to the statement "the
number of lines of <text>". So, even though you eventually delete every line
from tText, you end up in an infinite loop because the line count never goes
to zero. Instead, you have to use a separate "pick" list from which to
randomly choose index positions:

on GetRandomAnswerList
  set tText = member("Answers").text
  set tPicks = []
  repeat with i = 1 to the number of lines of tText
    tPicks.add(i)
  end repeat
  set tAnswerList = []
  repeat while tPicks.count > 0
    set tRand = random(tPicks.count)
    tAnswerList.add(tText.line[tPicks[tRand]])
    tPicks.deleteAt(tRand)
  end repeat
  return tAnswerList
end

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Christopher Watson
Sr. Software Engineer
Lightspan, Inc.
http://www.lightspan.com/
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


                -----Original Message-----
                From:   R Kumar [mailto:[EMAIL PROTECTED]]
                Sent:   Tuesday, February 13, 2001 12:37 PM
                To:     [EMAIL PROTECTED]
                Subject:        <lingo-l> Random display of questions

                Hi 

                I have a field which has 4 possible answers to a
                question. How do i randomly change the order in which
                the answers 
                appear, when the user enters the screen. Or is it
                advisable to do it with a list.

                Any help would be appreciated.

                ravi

                __________________________________________________
                Do You Yahoo!?
                Yahoo! Shopping - Thousands of Stores. Millions of Products.
                http://shopping.yahoo.com/

                [To remove yourself from this list, or to change to digest
mode, go to
                http://www.penworks.com/LUJ/lingo-l.cgi  To post messages to
the list,
                email [EMAIL PROTECTED]  (Problems, email
[EMAIL PROTECTED])
                Lingo-L is for learning and helping with programming Lingo.
Thanks!]

[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi  To post messages to the list,
email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo.  Thanks!]

Reply via email to