in UProveUnitTest/FieldZqTest.cs [199:241]
public void GetRandomElementsTest()
{
FieldZq Zq = FieldZq.CreateFieldZq(new byte[] { 0x05 });
// make sure that setting nonZero=true results in no no zero elements.
FieldZqElement[] nonZeroElements = Zq.GetRandomElements(30, true);
for (int i = 0; i < nonZeroElements.Length; ++i)
{
Assert.AreNotEqual(Zq.Zero, nonZeroElements[i], "element " + i + " is 0.");
}
// check that setting nonZero=false results in at least one zero element
bool foundNonZero = false;
FieldZqElement[] zeroElements = Zq.GetRandomElements(100, false);
for (int i = 0; i < zeroElements.Length; ++i)
{
if (zeroElements[i] == Zq.Zero)
{
foundNonZero = true;
break;
}
}
if (!foundNonZero)
{
Assert.Inconclusive("GetRandomElements did not create a single zero value. Try running this test again. Chances of failure on correct behavior is 0.0000000002.");
}
// check that setting maxBitLength=-1 results in at least one element 2, 3, or 4
bool foundLargeElement = false;
FieldZqElement[] fullScopeElements = Zq.GetRandomElements(100, false, -1);
for (int i = 0; i < fullScopeElements.Length; ++i)
{
if ((fullScopeElements[i] != Zq.Zero) && fullScopeElements[i] != Zq.One)
{
foundLargeElement = true;
break;
}
}
if (!foundLargeElement)
{
Assert.Inconclusive("GetRandomElements did not create a single value in the set {2,3,4}. Try running this test again. Chances of failure on correct behavior is 2.6 x 10^-40.");
}
}