neruda@tut.cis.ohio-state.edu (Steve Neruda) (01/04/88)
What is the fastest way to randomize a stack of quiz cards? I did it by assigning each card an invisible field, putting a random number into this field and then sorting by the field. This works fine but i rather slow Maybe this should be a built in option of the sort command (sort random). It is quite possible that I have overlooked an easier (faster way) so if you know of one please write. steve neruda
aisl@ur-tut.UUCP (Larry Landry) (01/05/88)
In article <3708@tut.cis.ohio-state.edu> neruda@tut.cis.ohio-state.edu (Steve Neruda) writes: > >What is the fastest way to randomize a stack of quiz cards? I did it by >assigning each card an invisible field, putting a random number into this field >and then sorting by the field. This works fine but i rather slow > I think that you have described the quickest way to do this in HyperCard. I implemented such a routine and it could shuffle 100 cards in less than 10 seconds. That seems quite reasonable for an interpreted system. The script that I use is shown below. on mouseUp set lockscreen to true set editBkgnd to true -- create new field in background doMenu "New Field" put the number of fields into fn -- number of background fields set editBkgnd to false put the number of cards into count repeat for count times put the random of 10000 into field fn go next card end repeat sort by field fn -- do the actual sort set editBkgnd to true -- delete the sorting field click at location of field fn doMenu "Cut Field" choose browse tool -- so the user can look at stack set editBkgnd to false set lockscreen to false end mouseUp It is important to use the index of the field if speed is your biggest concern since it is accessed quicker than the name of the field. The sort command is much faster than anything that you could write in a script If you were not using it, that is probably your problem. Larry Landry University of Rochester
winkler@apple.UUCP (Dan Winkler) (01/05/88)
A couple of other ways to get random cards: 1. You can randomly jump to cards with the command "go to any card". 2. Sorting works with any expression, so you can do "sort by random(100)". Dan.
dalea@cerebus.UUCP (Dale M. Arends X5706) (01/07/88)
Unless the intent is to hit every card once and only once each time through the stack, you could have a field in each card that holds a number. Then, put a statement such as "go to card with random(n) in field 'number'" in the mouseUp script of the next card button and the previous card button. This would allow chosing the next random card at the time it is needed. It isn't clean, but it works. The drawback is that some cards may be hit repeatedly while others may not be hit at all. -- -- Dale M. Arends (Fujitsu America Inc., San Jose, Calif.) {...}!amdahl!cerebus!dalea The opinions expressed herein do not necessarily reflect those of my employer. They are entirely my own if they make sense and I disavow them if they don't.