Macardam

Web Development Done Right

  • Home
  • Portfolio
  • WordPress Plugins
    • A Random Number
  • Contact

A Random Number

Note: As of July 2024, Macardam no longer manages the A Random Number plug-in. Please direct all questions and request to the WordPress support page.

—

A WordPress plugin that displays a random number on each page load. It truly is magic.

Here is a random number: 94

See? It works.

Get the Plugin

The plugin is available free on WordPress.org, or search for A Random Number under Plugins – Add New in the WP Admin. A premium version is in development which outputs a random universe on any WordPress page.

Documentation

To add a random number, just use the shortcode [arandomnumber] on any page, post, widget, or anywhere on your site. If you need to call the plugin from a page template, use the do_shortcode(); function, like this: <?php echo do_shortcode('[arandomnumber]'); ?>. You can add it as many times as you like on a page. Each time it’s called, it will display a unique random number.

Attributes

The [arandomnumber] shortcode accepts the following attributes:

  • min: Minimum number in range. Usage: min=1. (Optional. If used, the max attribute is required. Must be smaller than max. Default value 1.)
  • max: Maximum number in range. Usage: max=100. (Optional. If used, the min attribute is required. Must be larger than min. Default value 100.)
  • comma: Option to display or remove commas in the number. Usage: comma=no.(Optional. Default value yes.)

By default, the random number will have a range of 1 – 100. You can change the range of the random number by using min and max attributes:

[arandomnumber min=1 max=10000]: This will output a random number between 1 and 10,000. (Like this: 8,176)
[arandomnumber min=-500 max=-1]: This will output a random number between -500 and -1. (Like this: -148)
[arandomnumber min=50000000 max=60000000]: This will output a random number between 50,000,000 and 60,000,000. (Like this: 59,831,001)
[arandomnumber min=10000 max=20000 comma=no]: This will output a random number between 10,000 and 20,000, without the commas. (Like this: 17358)

Negative numbers are allowed. The total range of allowed numbers is really big. I tried a number with 27 characters and it still worked. Woah, that’s a lot of numbers. Just make sure min is smaller than max or you may break the Internet.

A Random Number Button

If shortcodes are too scary you can also use the A Random Number buttons on the Visual or Text tabs:

A Random Number Button

Click This Button

On the Visual tab, clicking it will open this pretty little window:

A Random Number Popup

Such a Pretty Modal

Add your values, or leave them blank, then press OK to add the random number. On the Text tab, pressing the button will add the shortcode with the min and max attributes. This is a shortcut so you don’t have to type it every time. Aren’t we nice?

Alright, that about covers it. Got it? Good.

Support

Why on Earth would you need support for this plugin? Well, if you insist, please submit a ticket on the plugin’s page on WordPress.org, or leave a comment below. Please allow at least one eternity for us to get back to you.

Changelog

v1.1: August 19, 2017

Details:

  • Added comma attribute to remove commas if needed.

v1.0: January 7, 2016

Details:

  • Launched A Random Number into the Internets. It’s alive!

Comments

  1. Serhan says

    August 19, 2017 at 1:42 pm

    Hi,

    I take the random number between 100000 and 999999 into a form then send it as an email creating a csv file. Therefore, the comma you use between each three digit is a problem for the csv file.

    I see this code part in your source but couldn’t ficure out how to fix it.

    • Macardam (Carl) says

      August 24, 2017 at 6:29 am

      Hi Serhan,

      Thanks for the feedback. I just released version 1.1 of the plug-in. Please update within your WordPress dashboard.

      This update adds a new “comma” attribute which can output the number without commas, as you requested. You can see the updated documentation for more details, but just add comma=no to the shortcode and you should be all set.

      If you have any further questions, let me know.

  2. Peter says

    October 4, 2017 at 11:38 am

    Hey there,

    It is possible to make the number stayed static? i want the number to stay static after the post being posted.

    Can it be done?

    Let me knoe

    • Macardam (Carl) says

      October 4, 2017 at 1:08 pm

      Hi Peter,

      Do you mean you want the number to be random when the post is a draft, but become static and no longer change on each page reload when the post is published?

      If so, I’m afraid that goes beyond the scope of this plug-in. I would recommend manually changing the shortcodes to static numbers.

      If you have any further questions, let me know.

      • Peter says

        October 5, 2017 at 2:38 am

        Hi Carl,

        Thanks so much for your fast reply, I really appreciate it.

        The reason it can’t be done manually is because a lot of these are mass generated so it is hard to edit every single outbound URL.

        But I found a solution, just create a spintax and find a poster that support spintax should get it fixed.

        • Macardam (Carl) says

          October 5, 2017 at 2:52 am

          Ah, that makes sense. Sorry I couldn’t have been more help, but I’m glad you found a solution!

          Cheers,
          Carl

  3. Rachel says

    October 11, 2017 at 7:08 am

    Hi, would like to use this plugin to generate random number per day, and hopefully the plugin can record in a database what the random number has been for the past days weeks years, is this possible? Thanks

    • Macardam (Carl) says

      October 11, 2017 at 1:13 pm

      Hi Rachel,

      Unfortunately, but that goes beyond the scope of this plug-in. It would take a lot of effort to make such a large scale change. This plug-in is meant to be used for simple purposes and the random number changes each time on page load. Sorry I couldn’t be more help.

      Cheers,
      Carl

  4. Mohammed Nayaz says

    November 16, 2017 at 1:55 pm

    Hi Macardam

    You have any plugins to assign different different number to register user

    Eg: For 1 user = 1 and 2nd user = 2

    If you have Please let me know that plugin

    Thanks & regards
    Mohammed Nayaz

    • Macardam (Carl) says

      November 29, 2017 at 4:48 am

      Hi Mohammed,

      Are you looking to change the ID(s) associated with user accounts? You could try something like this: https://wordpress.org/plugins/user-id-changer/ (Just to note, I’ve never used that plugin).

      My A Random Number plug-in isn’t integrated with users accounts. Sorry I couldn’t be more help.

      Cheers,
      Carl

  5. Dawn says

    March 3, 2018 at 5:27 am

    Hello, is this based on a true random number or pseudo-random algorithm?

    If true, is this based on qRNG or other source? Thanks!

    • Macardam (Carl) says

      March 3, 2018 at 5:32 am

      Hi Dawn,

      This plug-in uses the PHP function mt_rand: http://php.net/manual/en/function.mt-rand.php

  6. Dan Eng says

    September 1, 2018 at 6:12 am

    Hi,

    I love this plugin.
    I have one question; Is it possible to convert numbers (<1000) to text format so that the first 3 digits can be 0.

    For example:
    2 will be shown as 0002
    23 will be shown as 0023
    901 will be shown as 0901

    Thanks.

    • Macardam (Carl) says

      September 6, 2018 at 1:50 am

      Hi Dan,

      This probably wouldn’t be too complicated to do. Unfortunately, I’m just way too busy to make an update like this right now.

      What you could try to do is include the 0s statically. What if you did something like:

      000[arandomnumber min=1 max=9]
      00[arandomnumber min=10 max=99]
      0[arandomnumber min=100 max=999]

      Would that help you at all?

      Thanks!
      Carl

  7. Endrew says

    September 4, 2018 at 5:16 pm

    Hello, I would like to know if there is a possibility of finding a number already generated.

    • Macardam (Carl) says

      September 6, 2018 at 1:51 am

      Hi Endrew,

      I think I also just replied to your email. I’m really not sure what it is you”re looking to do here so if you could give me more details I’d try to help.

      Thanks,
      Carl

  8. Gb says

    December 21, 2018 at 11:10 am

    Hello!
    Is it possible to bound this generation with some button? I wan’t to add some button on my website page and generate random numbers everytime I press this button.
    Thanks.

    • Macardam (Carl) says

      January 6, 2019 at 1:58 am

      Sorry, I missed your comment somehow.

      This plug-in was made to be very simple. It loads a random number on the page based on the attributes provided. There isn’t a way to change this unless the page is reloaded and the function runs again.

      I would recommend looking at adding something like this to your website: https://www.random.org/widgets/

  9. Sanjay Yadav says

    April 19, 2020 at 1:52 pm

    Hi
    Thanks for reply. I have one more problem. I set my page to reload after every 14:45 minute. How can we add this generated no. to database so that I generate tabular chart for that day. The chart should be updated every 15:00 minute.

    Thanks.

    • Macardam (Carl) says

      April 20, 2020 at 5:06 pm

      Sorry, this goes beyond the scope of the plug-in. It’s only intended to output a random number each time the page is loaded. It doesn’t track or store anything.

  10. Jill Harkness says

    October 13, 2020 at 10:20 am

    Is there any way of keeping track of numbers that have been generated? I want to use this to randomize what training module is picked next – but obviously want to avoid duplication.

    • Macardam (Carl) says

      September 23, 2022 at 12:56 pm

      Sorry, that’s beyond the scope of this simple plug-in.

  11. Diego says

    October 31, 2020 at 10:30 pm

    Nice plugin…How do I send that random number, in a form, to use it as a unique identifier per message sent?
    I want to add a random number as a field in a form to be used as unique message identifier.

    can anybody help me?

    I work with “weForms plugin” in wordpress.

    Cheers 🙂

    • Macardam (Carl) says

      September 23, 2022 at 12:57 pm

      You should be able to use it anywhere a shortcode can be used. Not sure if it will work within form fields.

  12. Satria4D says

    December 25, 2020 at 4:27 pm

    Hello, first i want to say thank you for your usefull plug-in. It really fun 😀 But i have a little problem here.
    I make a button bellow The Random Number, and that button function is to refresh the page. So when i click the button the page will refresh it self.
    So what i want to ask is if it’s possible to generate a new number without refresh the page? So it’s like when we click the button the number will generated without refreshing page.

    Thank You.

    • Macardam (Carl) says

      September 23, 2022 at 12:58 pm

      This would be possible, but isn’t available at the moment. I’ll see about adding it sometime.

  13. Francesco Levrini says

    January 14, 2021 at 2:56 pm

    I have to generate a number from 1 to 52 with each click but without repetition. it’s possible?
    Thanks

    • Macardam (Carl) says

      September 23, 2022 at 12:58 pm

      Sorry, that’s beyond the scope of this simple plug-in.

  14. Ozb says

    September 23, 2022 at 12:14 pm

    Hi, how can i change the size or the color of the number?

    • Macardam (Carl) says

      September 23, 2022 at 1:01 pm

      You can apply any kind of styling. For example:

      <span style=”color:#30419a;font-size:24px;”>[arandomnumber]</span>

  15. Kay says

    November 29, 2022 at 1:07 pm

    Hi, I want to make sure I avoid repetition of the random numbers being generated, so I gave in a large allowance in between the parameters, something like 1 to 1000000. Then I’ll clear and reinstall the shortcode after a long while.

    Do you think I can avoid repetition with this method?

Web Developers Who Care

Matt Ricketts and Carl Carlson were born and raised in Ishpeming in the great Upper Peninsula of MI. They have been working online as Internet professionals since 2006 and highly enjoy the craftsmanship of designing, coding, and developing effective websites and products.

Contact Us by E-mail

  • This field is for validation purposes and should be left unchanged.

Or Directly

Matt Ricketts
906-869-1435
matt@macardam.com

Carl Carlson
906-360-3642
carl@macardam.com

Copyright © 2025 Macardam, LLC