• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Adobe script to generate random number

Community Beginner ,
Oct 17, 2018 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

1.6K

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
community guidelines
Community Expert ,
Oct 17, 2018 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

Votes

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
community guidelines
Community Expert ,
Oct 17, 2018 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.

Votes

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
community guidelines
Community Beginner ,
Nov 28, 2018 Nov 28, 2018

Copy link to clipboard

Copied

Care to elaborate?

Votes

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
community guidelines
Community Expert ,
Nov 28, 2018 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.

Votes

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
community guidelines
Community Beginner ,
Nov 28, 2018 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?

Votes

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
community guidelines
Community Expert ,
Nov 28, 2018 Nov 28, 2018

Copy link to clipboard

Copied

This is also possible.

Votes

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
community guidelines
Community Expert ,
Nov 28, 2018 Nov 28, 2018

Copy link to clipboard

Copied

LATEST

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.

Votes

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
community guidelines