Skip to main content
Participating Frequently
August 16, 2023
Question

Random number less then another number

  • August 16, 2023
  • 2 replies
  • 761 views

Hello,

 

I have a page property that runs a javascript action. It generates random numbers. I want the random number generated in "Number-2" to be less than the random number generated in "Number-1". How would I write this code? Please and thank you!

 

this.getField("Number-" + i).value = util.printf("%01d", Math.floor((______________));

This topic has been closed for replies.

2 replies

try67
Community Expert
Community Expert
August 16, 2023

You can use this code to do that:

 

this.getField("Number2").value = Math.floor(Math.random()*Number(this.getField("Number1").value)-0.0001);

Participating Frequently
August 16, 2023

Thanks, try67! I'm really just dealing with whole numbers so would I just change the "0.0001" to "1"?

 

Nesa Nurani
Community Expert
Community Expert
August 16, 2023

How many "Number-" fields you have?

If you have more than two, than number in second field should be less than number in first field and number in third field should be less than number in second field...etc?

Do you have a max or min random number limit?

Participating Frequently
August 16, 2023

The idea would be #2 is less than #1, #4 is less than number #3, an so on. So i guess it would be the even number should be less than the preceeding odd number. I am currently only going up to 40 numbers.

 

Nesa Nurani
Community Expert
Community Expert
August 16, 2023

Ok, but does the number #3 should also be less than number #2, or it can be higher?