Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
Send E-mail using Buddy API
Fireworks Xtra
Timeline re-direction and navigation
File Association and save
asASIOout
Viking board game
Volume Controller SWA(Shockwave Audio)
FileXtra
Animate Image Sequence
Set Quality of a QTVR Sprite
 

 

 

Behavior Random Integer - Shuffle

Added on 7/1/1999

 

Compatibilities:
D6_5 D7 D8 Mac PC Script

Rating:

Author: ColeTierney

A lingo object that returns non-repeating predefined random integers From Cole Tierney"s Code Corner http://homepages.together.net/%7Etierney/cole/code/

-- This parent script returns non-repeating predetermined random integers.
-- You can pass "new" either a list like: [ 1, 4, 3, 29 ] or a range like: 1, 10.

property lastVal, intLst, minVal, maxVal, numItems, numIndex

on new me, p1, p2  
  set the randomSeed = the ticks  
  set minVal = p1
  set maxVal = p2  
  set lastVal = 0
  set numIndex = 1  
  if listP( p1 ) then    
    set intLst = p1    
  else    
    set intLst = []
    repeat with i = minVal to maxVal
      append intLst, i
    end repeat    
  end if  
  set numItems = count( intLst )  
  shuffle me
  return me  
end

on shuffle me  
  if numItems > 1 then
    set the randomSeed = the timer
    set counter = 1    
    repeat while counter <= numItems      
      set ranIndex = random( numItems )      
      set value1 = getat( intLst, ranIndex )
      set value2 = getat( intLst, counter )      
      setat intLst, ranIndex, value2
      setat intLst, counter, value1      
      set counter = counter + 1
    end repeat
  end if  
end

on rand me  
  if numIndex > numItems then       -- NEED TO RESHUFFLE    
    shuffle me
    set numIndex = 1    
    set newVal = getat( intLst, numIndex )    
    if numItems > 1 then
      if newVal = lastVal then        -- MAKE SURE WE HAVE NO REPEATS
        deleteat( intLst, numIndex )  -- PUT IT AT THE END OF THE LIST
        append intLst, newVal
      end if
    end if    
  end if  
  set newVal = getat( intLst, numIndex )
  set lastVal = newVal
  set numIndex = numIndex + 1  
  return newVal  
end

 


Contact

MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA

Send e-mail