Test Data Manager

  • 1.  Is there a way to prevent duplicate data when using RANDDIGITS(MINLEN, MAXLEN)

    Posted Oct 05, 2016 03:04 PM

    Hello,

     

    I would like to create synthetic SSN using the RANDDIGITS(MINLEN, MAXLEN) function.  If I have table repeat count, will this function prevent duplicate SSNs from being generated?  My guess is no, this function will not prevent duplicate SSNs from being generated since they are random digits.  This is one example of the function I am using:  @randdigits(3,3)@@randdigits(2,2)@0000 resulting in something like '612040000'.  Is there a better way of generating synthetic SSN if I also need the table repeat count to be larger than 100?

     

    Thank you. 



  • 2.  Re: Is there a way to prevent duplicate data when using RANDDIGITS(MINLEN, MAXLEN)
    Best Answer

    Posted Oct 06, 2016 04:12 PM

    Hi Tam,

     

    You are right - Since RANDDIGITS generates random numbers there is a bleak possibility that the numbers might not be unique, especially when you are generating a large number of records.

     

    What you could use in this case is the NEXTVAL(SEQUENCE, STARTVAL) function. 

    This will return the next value in the specified sequence. If the sequence does not exist, a new one is created with a starting value of STARTVAL. Every subsequent call to the function increments the sequence by one.

     

    For your specific requirement (9-digit SSN), you could use something like:

    @nextval(MY_SSN,100000000)@

     

    Thanks,

    Sameer



  • 3.  Re: Is there a way to prevent duplicate data when using RANDDIGITS(MINLEN, MAXLEN)

    Posted Oct 13, 2016 04:03 PM

    Thank you for your suggestion Sameer.  I used both RandDigits and NextVal functions to create custom SSN numbers and that worked without duplications.

     

    Tam