Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Care to elaborate?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
How do you compare the new number to the content of the file?
Is it possible to bypass the generate a new number until you get a unique one? Like, generate a new number that exclude those that have already been generated?
I only want to generate a random number from 1 to 8. If the first generated number is "5", then the next time I want to generate the number, the only choices would be 1, 2, 3, 4, 6, 7, 8.
Is that possible?
Copy link to clipboard
Copied
This is also possible.
Copy link to clipboard
Copied
I explained how to do it.... If you want me to write the code for you I'm happy to do it for a small fee. You can contact me privately (try6767 at gmail.com) to discuss it further.