Adobe script to generate random number

Community Beginner ,
Oct 17, 2018

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

TOPICS
Acrobat SDK and JavaScript, Windows

Views

358

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Adobe script to generate random number

Community Beginner ,
Oct 17, 2018

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

TOPICS
Acrobat SDK and JavaScript, Windows

Views

359

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 17, 2018 0
Adobe Community Professional ,
Oct 17, 2018

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 17, 2018 0
Most Valuable Participant ,
Oct 17, 2018

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 17, 2018 0
New Here ,
Nov 28, 2018

Copy link to clipboard

Copied

Care to elaborate?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 28, 2018 0
Most Valuable Participant ,
Nov 28, 2018

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 28, 2018 0
New Here ,
Nov 28, 2018

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?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 28, 2018 0
Adobe Community Professional ,
Nov 28, 2018

Copy link to clipboard

Copied

This is also possible.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 28, 2018 0
try67 LATEST
Most Valuable Participant ,
Nov 28, 2018

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 28, 2018 0