wp_rand() WP 2.6.2
Generates a random number between the specified min and max.
This is a pluggable function, and it can be replaced by a plugin. It means that this function is defined (works) only after all plugins are loaded (included), but before this moment this function has not defined. Therefore, you cannot call this and all functions depended on this function directly from a plugin code. They need to be called on plugins_loaded hook or later, for example on init hook.
Function replacement (override) — in a plugin you can create a function with the same name, then it replace this function.
Basis of: wp_generate_password()
1 time = 0.000032s = very fast | 50000 times = 0.09s = speed of light | PHP 7.0.8, WP 4.6.1
No Hooks.
Return
Int. A random number between min and max
Usage
wp_rand( $min, $max );
- $min(int)
- Lower limit for the generated number
Default: 0 - $max(int)
- Upper limit for the generated number
Default: 0
Examples
#1 Basic usage
echo wp_rand( 99, 99999 ); // 19899, 85724, 77130, 51575 echo wp_rand( 1.5, 5.5 ); // 5, 1, 3, 4 echo wp_rand( 5, 4 ); // always 5
Notes
- Global. String. $rnd_value
Changelog
Since 2.6.2 | Introduced. |
Since 4.4.0 | Uses PHP7 random_int() or the random_compat library if available. |
Code of wp_rand() wp rand WP 5.6
Related Functions
From tag: PHP analogues (PHP functions replacement)
More from category: Helper Functions
- __return_empty_array()
- __return_empty_string()
- __return_false()
- __return_null()
- __return_true()
- __return_zero()
- build_query()
- get_page_hierarchy()
- get_temp_dir()
- human_readable_duration()
- is_email()
- is_php_version_compatible()
- is_serialized()
- is_serialized_string()
- is_wp_version_compatible()
- map_deep()
- maybe_serialize()
- maybe_unserialize()
- path_join()
- seems_utf8()
- stripslashes_deep()
- timer_stop()
- urlencode_deep()
- wp_array_slice_assoc()
- wp_debug_backtrace_summary()
- wp_doing_ajax()
- wp_extract_urls()
- wp_filter_object_list()
- wp_html_split()
- wp_is_json_request()
- wp_is_numeric_array()
- wp_is_uuid()
- wp_kses_array_lc()
- wp_kses_hair()
- wp_kses_uri_attributes()
- wp_list_filter()