SuperCard 談義室

乱数とロシア語学習プロジェクト

未翻訳ページです


From: withe009@maroon.tc.umn.edu (Sarah Withee)
Newsgroups: comp.sys.mac.hypercard
Subject: Random numbers in Supercard
Date: 19 Aug 1995 16:15:42 -0500

I am developing a flashcards routine for a Supercard Russian language 
learning project, and I am looking for a way to get Supercard to "pull 
numbers out of a hat" - to select numbers randomly without selecting the 
same number twice, and to keep selecting numbers until it has picked each 
number in the range.  Does anyone know of any function that will do this, 
or of some other way to solve the problem of getting the program to 
present the flashcards in a random order each time the program is run?  I 
have spent a number of hours trying to work something out, only to run up 
against brick walls.  I've seen routines in C for doing card shuffling 
and dealing simulations that are similar to what I want to be doing, but 
those require array variables, which don't seem to be available in 
Supercard (unless there's a feature like Director's list variables hiding 
out somewhere?).  Any suggestions would be much appreciated.


From: Jeff Benjamin 
Newsgroups: comp.sys.mac.hypercard
Subject: Re: Random numbers in Supercard
Date: 19 Aug 1995 21:39:26 GMT

The Random() function is they key. But making sure you don't get the same 
one twice is tricky. Here's a handler(s) which I think will work. It's not 
tested, as I'm coding 'on the fly' here:

At the beginning of a lesson, do this:

    on initLesson numberOfCards
       global gUnusedCards 

       repeat with i = 1 to numberOfCards
           put i & "," after gUnusedCards
       end repeat
       delete last char of gUnusedCards  -- get rid of last comma
    end initLesson

To get the next random card #, call this function:

    function getRandomCardNumber
        global gUnusedCards 
  
        set the itemDel to ","
        put the number of items of gUnusedCards into totalUnused
        put random(totalUnused) into whichItem
        put item whichItem of gUnusedCards into anUnusedCardNum
        delete item whichItem of gUnusedCards  -- this one is no longer unused
        return anUnusedCardNum
    end getRandomCardNumber


Hope that helps!

-------------------------------------------------
+                Jeff Benjamin                         
+                StepUp Software                    
+                stepup@onramp.net
+                http://rampages.onramp.net/~stepup/
-------------------------------------------------


From: bmolyneaux@aol.com (BMolyneaux)
Newsgroups: comp.sys.mac.hypercard
Subject: Re: Random numbers in Supercard
Date: 20 Aug 1995 15:48:17 -0400

Here is some code that will do what you want (I think, it's totally
untested....). It is probably fine for small sets of numbers but as the
range gets larger, it will probably get slower fast.

--Brian

put "1,2,3,4,5,6,7,8,9,10,11,12,13,14" into numSet
 get 0
 repeat until it is in numSet
   get random(max(numSet))
 end repeat
 put it into randNum
  repeat with i=1 to the number of items in numSet
   if item i of numSet is randNum then
     delete item i of numSet
     exit repeat
    end if
  end repeat
  -- do something with randNum


From: tigger@satyr.sylvan.com (Grace Sylvan)
Newsgroups: comp.sys.mac.hypercard
Subject: Re: Random numbers in Supercard
Date: 03 Sep 1995 12:18:43 -0700

Here is a simple loop that will do this, I used it in ChristmasTime to
scramble the order of the cards I display. My first list, called
list1, is a list of all the names (in order) and it's got 14 elements,
I scramble the list by picking 1 item at random, appending it to the
new list (list2) with a space added and then removing it from list1.
Then, because I'm in a loop, it picks from list 1 again, and so on.

 put empty into list2
 repeat with i = 14 down to 2
  put random(i) into danum
  put word danum of list1 & " " after list2
  delete word danum of list1
 end repeat
 put word 1 of list1 after list2

Of course, if your cards are numbers, you can generate list 1 quickly
with a simple loop.

If you need more help/suggestions, just let us know.


-- 
Tigger (Grace Sylvan)                Mom of Katherine Yelena, 6,
tigger@satyr.sylvan.com              Robin Gregory, 3.5
Children's Shareware Pages:          http://www.sylvan.com



このホームページは、いぜんとして構築中です。もし SCUJ ホームページ についてご質問やご意見がございましたら、以下のホームページ管理者までメールにて ご連絡下さい。

ホームページ管理者: 大島 久雄
電子メールアドレス: oshima@kyushu-id.ac.jp