You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Provides pool status monitoring (empty detection, item count query)
Supports duplicate merging and cleanup
Usage Examples
Basic Usage
# Initialize pool (disable auto-rebuild and duplicate check for performance)varpool=CoreSystem.RandomPicker.new([
["sword", 10],
{"data": "gem", "weight": 5}
], check_repeat=false)
# Add single item (manual rebuild control)pool.add_item("shield", 8.0, rebuild=false, check_repeat=false)
# Batch add with manual rebuildvarnew_items= [
["potion", 15],
{"data": "key", "weight": 1}
]
pool.add_items(new_items, rebuild=false)
pool.rebuild_alias_table() # Explicit rebuild# Get random item (non-removal)varloot=pool.get_random_item()
# Batch remove with auto-rebuildpool.remove_items(["sword", "gem"], rebuild=true)
Dynamic Operations & Signals
# Connect signalspool.item_picked.connect(func(item):
print("Selected:", item)
)
pool.pool_emptied.connect(func():
print("★ Pool emptied!")
)
# Update weight and trigger rebuildpool.update_item_weight("potion", 20.0)
pool.add_item("dragon_sword", 5.0)
# Empty pool (trigger signal)whilenotpool.is_empty():
pool.get_random_item(true) # Remove selected
Best Practices
Data Validity:
Weights must be positive, otherwise operations are rejected
Returns null for get_random_item when total weight is 0
Performance Optimization:
For high-frequency operations (e.g., batch adds), disable rebuild and check_repeat, call rebuild_alias_table() manually.
Stress tests show 100k items pool averages <0.001ms per random access, but ~580ms initialization (lightweight laptop). Manage duplicates carefully for large datasets.
Set check_repeat=false during initialization if duplicates are impossible (saves ~100ms for 100k items).