ubegun/Cybercat

Get random element from GroupElements<>()

Closed this issue · 1 comments

Hi there,
I have problem to get random element from GroupElements. In some cases content of the list is dynamic and may contain only one element. This causes exception generated by "rand.nextInt(ind)" in "CommonUtils.generateNumber(ind)", because "ind" will be zero.

public T getElementRandom() {
return subElements.get(CommonUtils.generateNumber(subElements.size() - 1));
}

As a solution I propose to use ternary ?: operator in "get()" function.

done