arrayspowershellrandomsequential-number

Generate unique semi random numeric strings


I want to generate 10k of unique numbers composed of a sequential number (16 digits) followed by a random numeric string (4 digits). Weapon of choice is Powershell because it's the only tool I have a very limited knowledge of.

Problems encountered:

  1. Generating 10k sequential numbers using the following method: 1400000000000000..1400000000010000 and putting into a variable. Error: Value is to large for an Int32
  2. Generating 10k of 4 digit via Get-Random -Minimum 0001 -Maximum 9999 and putting them in a variable. I manage only to obtain 1 random number.
  3. Combining the two variables using the Join-Object (or at least that's what I hope could be done)

How can I combine these 3 commands to obtain a list of semi random numbers as specified above? Or is there simpler way to achieve the same result?


Solution

  • (0..10000).ForEach{ '14000000000{0:00000}{1:0000}' -f $_, (Get-Random 10000) }
    

    Result:

    14000000000000004965
    14000000000000010114
    14000000000000026382
    14000000000000038644
    14000000000000045435
    14000000000000052051
    14000000000000061801
    14000000000000077046
    14000000000000087791
    14000000000000098090
    14000000000000102712
    ....
    

    Explanation: