Title: Random functions
Last modified: September 7, 2018

---

# Random functions

 *  Resolved [altkmv](https://wordpress.org/support/users/altkmv/)
 * (@altkmv)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/random-functions/)
 * Hello there!
 * Help to deal with the problem. I want to make button, when you press it – select
   randomly number. From 0 to 9. And, depending on the resulting number, the text
   field was shown.
 * I tried to create a button and paste it “Math.floor (Math.random () * 10);”. 
   And then try pass the value to the calculated field. But I did not succeed.
 * Tell me, how to do it right?

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/random-functions/#post-10666210)
 * Hello [@altkmv](https://wordpress.org/support/users/altkmv/).
 * The piece of code: `Math.floor (Math.random () * 10);` is correct, even if you
   are using our plugin it could be implemented as `FLOOR(RANDOM()*10)` without 
   the Math object, but with your description it is not clear the way you are assigning
   the random number to the fields, or the way you are using this number.
 * Please, send me the link to the webpage where the form is inserted and describe
   the process.
 * Best regards.
 *  Thread Starter [altkmv](https://wordpress.org/support/users/altkmv/)
 * (@altkmv)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/random-functions/#post-10666340)
 * Here is the test page: [https://irongeneration.ru/akcii](https://irongeneration.ru/akcii).
   I want to understand the principle and do it right
 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/random-functions/#post-10666740)
 * Hello [@altkmv](https://wordpress.org/support/users/altkmv/),
 * The process was not implemented as should, you cannot use the button as an operand
   in the equation, because the buttons don’t have an onchange event. So, the equation
   would be as follows:
 * 1. Insert a hidden field in the form, I’ll call it the fieldname123
    2. Edit 
   the onclick event of the button as follows:
 *     ```
       jQuery('[id*="fieldname123_"]').val(FLOOR(RANDOM()*10)).change();
       ```
   
 * 3. Finally, edit the equation associated to the calculated field to use the hidden
   field inserted in the first step.
 * and that’s all.
 * Note that the fields’ names are generated dynamically, so, in the previous code
   you should use the corresponding field’s name.
 * Best regards.
 *  Thread Starter [altkmv](https://wordpress.org/support/users/altkmv/)
 * (@altkmv)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/random-functions/#post-10666859)
 * Thanks alot!
 * Whether correctly I understood, I create a calculated field. By this equation
   I gain the value this calculated field and if the value is 1, then I output the
   field 1, the value 2 – the field 2, etc.?
 * Apparently, I again understand everything is not entirely correct, because the
   display of the fields does not work (as if the field is always 0).
 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/random-functions/#post-10667389)
 * Hello [@altkmv](https://wordpress.org/support/users/altkmv/),
 * I’m sorry, I don’t understand what do you mean with the fields to display, but
   if you want to display some fields based on the equation’s results, you simply
   should defined dependencies in the settings of calculated field.
 * By the way, I think that would be better if you move the code that generate the
   random number directly to the equation, run this code in the onclick event only
   for assigning the generated number to the calculated field, has no sense. In 
   this case you can include the piece of code that generates the random number 
   as part of the equation:
 *     ```
       (function(){
       return FLOOR(RANDOM()*10);
       })()
       ```
   
 * Best regards.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Random functions’ is closed to new replies.

 * ![](https://ps.w.org/calculated-fields-form/assets/icon-256x256.jpg?rev=1734377)
 * [Calculated Fields Form](https://wordpress.org/plugins/calculated-fields-form/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/calculated-fields-form/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/calculated-fields-form/)
 * [Active Topics](https://wordpress.org/support/plugin/calculated-fields-form/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/calculated-fields-form/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/calculated-fields-form/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [codepeople](https://wordpress.org/support/users/codepeople/)
 * Last activity: [7 years, 8 months ago](https://wordpress.org/support/topic/random-functions/#post-10667389)
 * Status: resolved