[comp.sys.mac.hypercard] XFCN--randomly selecting a word from a field

dragon@hubcap.clemson.edu (Michael E. Quattlebaum) (12/14/89)

I need an XFCN that will go out and randomly select a word from a
field.  This will be used in an educational stack that selects 
words for a student to practice a spelling excercise.  I will be
willing to write this if need be, but why reinvent the wheel, huh?
Please send e-mail with ftp sites, etc.  if such a beast exists.
  
Thanks.

marvel@giza.cis.ohio-state.edu (Howard P Marvel) (12/14/89)

In article <7417@hubcap.clemson.edu> dragon@hubcap.clemson.edu (Michael E. Quattlebaum) writes:
>I need an XFCN that will go out and randomly select a word from a
>field.  This will be used in an educational stack that selects 
>words for a student to practice a spelling excercise.  I will be
>willing to write this if need be, but why reinvent the wheel, huh?
>Please send e-mail with ftp sites, etc.  if such a beast exists.

Why do you need an XFCN?  

	put the number of words in field spell into foo
	put word random(foo) of field spell into spellword

I haven't tried this, but it looks ok.

martin@m2.csc.ti.com (Steven Martin) (12/14/89)

In article <74944@tut.cis.ohio-state.edu> Howard P Marvel <marvel@cis.ohio-state.edu> writes:
>In article <7417@hubcap.clemson.edu> dragon@hubcap.clemson.edu (Michael E. Quattlebaum) writes:
>>I need an XFCN that will go out and randomly select a word from a
>>field.  This will be used in an educational stack that selects 
>>words for a student to practice a spelling excercise.  I will be
>>willing to write this if need be, but why reinvent the wheel, huh?
>>Please send e-mail with ftp sites, etc.  if such a beast exists.
>
>Why do you need an XFCN?  
>
>	put the number of words in field spell into foo
>	put word random(foo) of field spell into spellword
>
>I haven't tried this, but it looks ok.

Yecchh! :-)  How about:

any word of field spell

It's amazing how many little commands like this there are and how few
people actually know about them.

Steve Martin            USENET: {ctvax,im4u,texsun,rice}!ti-csl!martin
                        ARPANET: SMARTIN@CSC.TI.COM  COMPUSERVE: 72727,1471
                        GENIE: S.MARTIN8    PHONE: (214)-995-0387, 404-1061
I'll have four whole fried chickens and a Coke. -Jake Blues

jdevoto@Apple.COM (Jeanne A. E. DeVoto) (12/15/89)

In article <7417@hubcap.clemson.edu> dragon@hubcap.clemson.edu
(Michael E. Quattlebaum) writes:
>I need an XFCN that will go out and randomly select a word from a
>field.  This will be used in an educational stack that selects 
>words for a student to practice a spelling excercise.  I will be
>willing to write this if need be, but why reinvent the wheel, huh?

No need for an XFCN. This can be done with the following line:

  get any word of field "foobar"
-- 
====== jeanne a. e. devoto ========================================
 jdevoto@apple.com  |  You may not distribute this article under a
 jdevoto@well.UUCP  |  compilation copyright without my permission.
___________________________________________________________________
 Apple Computer and I are not authorized  |        CI$: 72411,165
 to speak for each other.                 |  AppleLink: SQA.TEST

llkl@uhura.cc.rochester.edu (Laurie Kleiner) (12/15/89)

In article <74944@tut.cis.ohio-state.edu> Howard P Marvel <marvel@cis.ohio-state.edu> writes:
>In article <7417@hubcap.clemson.edu> dragon@hubcap.clemson.edu (Michael E. Quattlebaum) writes:
>>I need an XFCN that will go out and randomly select a word from a
>>field.  This will be used in an educational stack that selects 
>>words for a student to practice a spelling excercise.  I will be
>>willing to write this if need be, but why reinvent the wheel, huh?
>>Please send e-mail with ftp sites, etc.  if such a beast exists.
>
>Why do you need an XFCN?  
>
>	put the number of words in field spell into foo
>	put word random(foo) of field spell into spellword
>

If you don't want the words to be repeated within a test, then it's better
to get the total number of words in the field, pick a random number, get 
the coresponding word, delete the nth word in the field.  ie:
	put the number of words in field spell into foo
	put the random of number into bar
	put word bar of field spell into spellword
	delete word bar of field spell
Getting the random number can be slow, and random doesn't work with values
over 32767.


-- 
-------------------------------------------------------------------------------
Laurie Kleiner                                     LLKL_SS@DB1.CC.ROCHESTER.EDU 
            Old enough to know better, stupid enough to do it anyhow. 
-------------------------------------------------------------------------------

rieman@boulder.Colorado.EDU (John Rieman) (12/16/89)

>[... example of using random() ...]
>
>Yecchh! :-)  How about:
>
>any word of field spell
>
>It's amazing how many little commands like this there are and how few
>people actually know about them.
>
>Steve Martin            

Hardly amazing, since Apple doesn't bother to distribute a complete
reference to Hypertalk with HyperCard.  Anyway, I like the "random()"
solution as well or better.  It's clear what it does, and it admits to
easy modification (e.g., deleting the word after selecting it, as
suggested in another posting).  But mostly that reflects my preference
for a minimal set of commands and functions.  I can see how someone else
might prefer "any" in this case.

Does anyone know how random "random()" really is?  

-john

rieman@boulder.colorado.edu
U. of Colo.