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

Generating a Random number

New Here ,
Feb 01, 2018 Feb 01, 2018

Copy link to clipboard

Copied

I am completely new at javascript and I don't know all the terminology so it might take some dumbing down in response. I am attempting to generate a random number between 0 and 1 so I would like it to look like .1234 or .9999. It has to be four digits and I don't necessarily need it to lock once entered. I would only need to print that page and hit my radio button and generate a new list of numbers. I currently have this as my script.

this.getField("Text1").value =

Math.floor(Math.random()/Math.pow(10000,4));

The "Text1" is the current name for the box on my test page and I am using a radio button to generate the number. I will also have multiple boxes that I want random numbers generated in and I would like to use one radio button to complete the task of generating all the random numbers that I would need. How would I also add, say "text2, text3, text4", boxes to this so that all of them would have a separate random number or do I have to enter a script to each "text" box to do this.

Thanks 

TOPICS
Acrobat SDK and JavaScript , Windows

Views

419

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

correct answers 1 Correct answer

Community Expert , Feb 01, 2018 Feb 01, 2018

JavaScript Random numbers are already between 0 and 1, so all you need is some formatting.

this.getField("Text1").value = Math.random().toString().substr(0,6);

Votes

Translate

Translate
Community Expert ,
Feb 01, 2018 Feb 01, 2018

Copy link to clipboard

Copied

LATEST

JavaScript Random numbers are already between 0 and 1, so all you need is some formatting.

this.getField("Text1").value = Math.random().toString().substr(0,6);

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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