Skip to main content
buddycafe
Known Participant
October 17, 2018
Question

Adobe script to generate random number

  • October 17, 2018
  • 2 replies
  • 1999 views

Hello,

Is is there a way to insert a button to a PDF that would generate a random number (up to 10 numerical characters) but never repeat the same numbers for every time the button is clicked? Any help is appreciated.

Thank you,

Ed

This topic has been closed for replies.

2 replies

try67
Community Expert
Community Expert
October 18, 2018

If you want the number not to repeat you will need to keep a record of all

previous numbers and compare the new number to it when generating it.

Known Participant
November 28, 2018

Care to elaborate?

try67
Community Expert
Community Expert
November 28, 2018

Add a hidden text field and put each number you generate into it.

When generating a new number, compare it to the contents of that file. If a match is found, generate a new number, until you get a unique one. Then add it to the field as well, and repeat.

Joel Geraci
Community Expert
Community Expert
October 18, 2018

You won't be able to generate a random number with no chance of repeats using any computer language. There are just pseudo-random number algorithms which will get you close. Look at the JavaScript Math object. The code below will generate a random number from 0 to 99.

Math.floor(Math.random() * 100);

What you really want is an alpha-numeric Universally Unique Identifier. You can find one of those here...

http://blogs.cozi.com/tech/2010/04/generating-uuids-in-javascript.html