A WordPress plugin that displays a random number on each page load. It truly is magic.
Here is a random number: 38
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: 1,001)
[arandomnumber min=-500 max=-1]
: This will output a random number between -500 and -1. (Like this: -31)
[arandomnumber min=50000000 max=60000000]
: This will output a random number between 50,000,000 and 60,000,000. (Like this: 59,933,358)
[arandomnumber min=10000 max=20000 comma=no]
: This will output a random number between 10,000 and 20,000, without the commas. (Like this: 14885)
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:
On the Visual tab, clicking it will open this pretty little window:
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!
Serhan says
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
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.
Peter says
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
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
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
Ah, that makes sense. Sorry I couldn’t have been more help, but I’m glad you found a solution!
Cheers,
Carl
Rachel says
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
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
Mohammed Nayaz says
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
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
Dawn says
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
Hi Dawn,
This plug-in uses the PHP function mt_rand: http://php.net/manual/en/function.mt-rand.php
Dan Eng says
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
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
Endrew says
Hello, I would like to know if there is a possibility of finding a number already generated.
Macardam (Carl) says
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
Gb says
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
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/
Sanjay Yadav says
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
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.
Jill Harkness says
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
Sorry, that’s beyond the scope of this simple plug-in.
Diego says
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
You should be able to use it anywhere a shortcode can be used. Not sure if it will work within form fields.
Satria4D says
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
This would be possible, but isn’t available at the moment. I’ll see about adding it sometime.
Francesco Levrini says
I have to generate a number from 1 to 52 with each click but without repetition. it’s possible?
Thanks
Macardam (Carl) says
Sorry, that’s beyond the scope of this simple plug-in.
Ozb says
Hi, how can i change the size or the color of the number?
Macardam (Carl) says
You can apply any kind of styling. For example:
<span style=”color:#30419a;font-size:24px;”>[arandomnumber]</span>