new RandomSet(contents) → {platypus.RandomSet}
This class defines a set that is populated and then pulled from at random. When pulled from, the set will return copies of the contents such that all the contents in the set are used once before there are repeats. Repeats may still occur when the set has been used up or when the number of items requested is greater than the size of the set.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
contents |
array
|
The contents that will populate the set. |
Methods
(static) recycle(randomSet)
Returns a RandomSet back to the cache.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
randomSet |
platypus.RandomSet
|
The RandomSet to be recycled. |
(static) setUp() → {platypus.RandomSet}
Returns an RandomSet from cache or creates a new one if none are available.
- Source:
add(toAdd)
Add single element to the content set. Includes the new content in the current set, which means it be returned quickly depending on the remaining set size.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
toAdd |
primitive
|
Object
|
Content to add to the set. |
get() → {primitive|Object}
Get a random member of the set.
- Source:
Returns:
- Type:
-
primitive
|Object
A random member of the set
getMultiple(numberToGet) → {primitive|Object}
Get an array of random set members. There may be multiple of the same member in the set if the quantity requested is greater than the set size, or the set is exhausted and replenished while retrieving members.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
numberToGet |
integer
|
Number of set members to retrieve |
Returns:
- Type:
-
primitive
|Object
A random member of the set
remove(toRemove, removeAll)
Remove from the content set. Use removeAll if you want to remove all instances, otherwise only removes the first instance found.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
toRemove |
primitive
|
Object
|
Content to remove from the set. |
removeAll |
boolean
|
Remove all instances of the primitive/object. |