0

For the following code, using "CreateRandomString":

<ClaimsTransformations>
            <ClaimsTransformation Id="SetRandomNumber" TransformationMethod="CreateRandomString">
                <InputParameters>
                    <InputParameter Id="randomGeneratorType" DataType="string" Value="INTEGER"/>
                    <InputParameter Id="maximumNumber" DataType="int" Value="10"/>
                    <InputParameter Id="seed" DataType="int" Value="1234567890"/>
                    <InputParameter Id="stringFormat" DataType="string" Value="{0}"/>
                    <InputParameter Id="base64" DataType="boolean" Value="false"/>
                </InputParameters>
                <OutputClaims>
                    <OutputClaim ClaimTypeReferenceId="randomNumber" TransformationClaimType="outputClaim"/>
                </OutputClaims>
            </ClaimsTransformation>
        </ClaimsTransformations>

where I want a random number between 0 and 10, it always returns 5.

For 1000 values, always returns 547. For 100 values, always returns 54. For 10 values, always returns 5. For 3 values, always returns 1.

It just seems to pick a number in the middle of the range.

Is there something I can do to get a random number in the same manner that the C# Random method works?

rbrayb
  • 46,440
  • 34
  • 114
  • 174

1 Answers1

1

The documentation mentions the following notes for the seed value:

[Optional] For INTEGER randomGeneratorType only. Specify the seed for the random value. Note: same seed yields same sequence of random numbers.

The seed value allows you to make sure you get the same sequence in case your policy depends on that sequence for some reason.

As mentioned in the example in the documentation, you should eliminate the seed value altogether when calling this transformation to guarantee a different sequence every time.

<ClaimsTransformation Id="SetRandomNumber" TransformationMethod="CreateRandomString">
  <InputParameters>
    <InputParameter Id="randomGeneratorType" DataType="string" Value="INTEGER" />
    <InputParameter Id="maximumNumber" DataType="int" Value="1000" />
    <InputParameter Id="stringFormat" DataType="string" Value="OTP_{0}" />
    <InputParameter Id="base64" DataType="boolean" Value="false" />
  </InputParameters>
  <OutputClaims>
    <OutputClaim ClaimTypeReferenceId="randomNumber" TransformationClaimType="outputClaim" />
  </OutputClaims>
</ClaimsTransformation>

Try eliminating the seed value as it should be fine.

Source: https://learn.microsoft.com/en-us/azure/active-directory-b2c/string-transformations#createrandomstring

  • Clearly, I missed that bit of documentation! Yes, works now. But agree, wondering what the purpose of the seed is? – rbrayb Apr 22 '21 at 22:31