Title: Random computer generated scores
Last modified: September 11, 2023

---

# Random computer generated scores

 *  [rowdogz](https://wordpress.org/support/users/rowdogz/)
 * (@rowdogz)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/random-computer-generated-scores/)
 * Hi All,
 * I know the system can help when a user does not enter one of the scores and will
   set it to ‘0’ to complete the prediction. what I was wondering is, has any built
   an add-on that can actually generate random scores for any game that a user has
   not completed prior to the lockout time? My theory is that said users might not
   be able to add fixtures but the random prediction will help them.

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

 *  Thread Starter [rowdogz](https://wordpress.org/support/users/rowdogz/)
 * (@rowdogz)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/random-computer-generated-scores/#post-17061448)
 * [AntoineH](https://wordpress.org/support/users/antoineh/) – I wonder if it is
   possible for me to use the same mechanism you created to fix the missing predictions
   to allow me to create the computer generated random scores for users. Can I Ask
   where about this code is?
 *  Plugin Author [AntoineH](https://wordpress.org/support/users/antoineh/)
 * (@antoineh)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/random-computer-generated-scores/#post-17061563)
 * Weird… where did my precious answer go? I thought I answered to this question
   😀
 * The mechanism to change the scores is in the `calc_score` method of the `Football_Pool_Pool`
   class. This method also contains a hook that you can use to overwrite the function.
   I use this mechanism also in the [Golden Games](https://wordpress.org/support/topic/extension-plugins-for-the-football-pool-plugin/#post-8998136)
   add-on.
 *  Thread Starter [rowdogz](https://wordpress.org/support/users/rowdogz/)
 * (@rowdogz)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/random-computer-generated-scores/#post-17061982)
 * [AntoineH](https://wordpress.org/support/users/antoineh/) – Thank you. I have
   added this in but its hard for me to check if its working. It should be checking
   if a user has entered a home or away score and add a random number between 0-
   60 on any missing scores:
   $user_home_is_valid = is_numeric($user_home); $user_away_is_valid
   = is_numeric($user_away); // Check if the user has provided predictions for both
   home and away teams if ($user_home_is_valid && $user_away_is_valid) { $user_home
   = (int) $user_home; $user_away = (int) $user_away; } else { // User prediction
   not complete for one or both teams // Set random scores between 0 and 60 for 
   missing predictions if (!$user_home_is_valid) { $user_home = rand(0, 60); } if(!
   $user_away_is_valid) { $user_away = rand(0, 60); } }
 *  Plugin Author [AntoineH](https://wordpress.org/support/users/antoineh/)
 * (@antoineh)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/random-computer-generated-scores/#post-17062078)
 * If you want to check your code, you’ll need to create some test users and test
   matches. Write out some scenarios, add the test data and then check in the plugin
   and/or database if you get the expected values. Shouldn’t be too hard to test.
 *  Thread Starter [rowdogz](https://wordpress.org/support/users/rowdogz/)
 * (@rowdogz)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/random-computer-generated-scores/#post-17074822)
 * The current ‘fix incomplete’ method – does it update the users prediction in 
   the DB from ‘NULL’ to ‘0’ or is it meant to leave it as ‘NULL’
 *  Plugin Author [AntoineH](https://wordpress.org/support/users/antoineh/)
 * (@antoineh)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/random-computer-generated-scores/#post-17074853)
 * It only ‘assumes’ a 0 when doing the calculation. If I also updated the database,
   you would never have the option to disable the option again and go back to the
   previous state.
 *  Thread Starter [rowdogz](https://wordpress.org/support/users/rowdogz/)
 * (@rowdogz)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/random-computer-generated-scores/#post-17075147)
 * Ah that makes sense – I was testing and it kept changing the users awarded points
   but it must be randomly predicting the missing score each time and thus changing
   the outcome every time the calc method runs. I think I need to add a method that
   predicts missing scores for a user and adds it to the DB to make it permanent.
   I was thinking I could create a method that does this when the match is locked
   for editing.
 *  Plugin Author [AntoineH](https://wordpress.org/support/users/antoineh/)
 * (@antoineh)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/random-computer-generated-scores/#post-17075186)
 * You can also do it when doing the calculation. Indeed, just update the DB for
   the ones containing a NULL value. Can be done in two queries (one for home and
   one for away). On a next calculation these values are permanent and won’t be 
   updated again.
 * Something like this for the home score prediction:
 *     ```wp-block-code
       UPDATE pool_wp_predictions 
       SET home_score = FLOOR(RAND()*(b-a+1))+a 
       WHERE home_score IS NULL
       ```
   
 * Where `a` and `b` are the min and max values for your predictions (e.g., a = 
   0 and b = 5).

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

The topic ‘Random computer generated scores’ is closed to new replies.

 * ![](https://ps.w.org/football-pool/assets/icon-256x256.png?rev=983880)
 * [Football Pool](https://wordpress.org/plugins/football-pool/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/football-pool/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/football-pool/)
 * [Active Topics](https://wordpress.org/support/plugin/football-pool/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/football-pool/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/football-pool/reviews/)

 * 8 replies
 * 2 participants
 * Last reply from: [AntoineH](https://wordpress.org/support/users/antoineh/)
 * Last activity: [2 years, 8 months ago](https://wordpress.org/support/topic/random-computer-generated-scores/#post-17075186)
 * Status: not a support question