Naanou.Common
Class RandomArrayCrawler

Provides random indexes to an array.

Not thread safe

Field Summary
bool autoReset
int givenOut
bool[] indexes
System.Random r

Constructor Summary
RandomArrayCrawler(int length, bool autoReset)
         Constructor

Method Summary
int GetIndex()
         Gets a random index. If autoReset is false and there are no more indexes, -1 is returned
void Reset()
         Reset indexes (old numbers are then re-used)

Methods inherited from class System.Object
Equals, Finalize, GetHashCode, GetType, MemberwiseClone, ToString


Field Detail

autoReset

private bool autoReset


givenOut

private int givenOut


indexes

private bool[] indexes


r

private System.Random r

Constructor Detail

RandomArrayCrawler

public RandomArrayCrawler(int length,
                          bool autoReset)

Constructor

Parameters:
length - Number of indexes
autoReset - Should numbers wrap-around automatically
Method Detail

GetIndex

public int GetIndex()

Gets a random index. If autoReset is false and there are no more indexes, -1 is returned

Returns:
Random index, or -1 if autoReset is false and there are no more indexes

Reset

public void Reset()

Reset indexes (old numbers are then re-used)