Generating a Random number

New Here ,
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 

Adobe Community Professional
Correct answer by Thom Parker | Adobe Community Professional

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);

TOPICS
Acrobat SDK and JavaScript, Windows

Views

187

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

Generating a Random number

New Here ,
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 

Adobe Community Professional
Correct answer by Thom Parker | Adobe Community Professional

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);

TOPICS
Acrobat SDK and JavaScript, Windows

Views

188

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
Feb 01, 2018 0
Adobe Community Professional ,
Feb 01, 2018

Copy link to clipboard

Copied

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);

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...
Feb 01, 2018 0