Hi all,
Error is displayed when trying to create 16 digit fixed length random number
I am assigning an int variable as:
intRandomNumber= New Random() Next(1000000000000000,9999999999999999)
But its showing error as ‘Constant expression not representable in integer’
Even if i selected variable type as ‘Double’ it’s giving me similar error.
Hi
The next method accepts only Int32 values. Largest int32 number have only 10 digits.
But you can split generating into 2 parts:
generate first 8 digits:
random.Next(10000000,99999999)
Convert this number to decimal, multiple by 10000000 and add to second 8-digits random number:
random.Next(00000000,99999999)
Now you should have 16-digits random value from 1000000000000000-9999999999999999.
I recommend to use decimal instead of double in this case (double have 15-17 digits precision)
To generate a 16-digit random number, you can use a different data type, such as a Long or a Decimal , which can represent larger values. Here is an example of how you could generate a 16-digit random number using a Long data type.
Random random = new Random()
long intRandomNumber = random.Next(1000000000000000L, 9999999999999999L)
Thanks @Konrad_Mierzwa for the reply.
I tried as you told.
But it’s still giving me same error as mentioned in my query
I am using int64 as variable type for the number but still same issue
thanks for your response.
I can’t choose when starting a new process and I don’t see in studio, there is nothing in brackets behind ‘Dependecies’.
Maybe it is due to company policy or it is because we still have an old version of studio: 2019.10