search
Search
Unlock 100+ guides
search toc
close
Cancel
Post
account_circle
Profile
exit_to_app
Sign out
What does this mean?
Why is this true?
Give me some examples!
search
keyboard_voice
close
Searching Tips
Search for a recipe:
"Creating a table in MySQL"
Search for an API documentation: "@append"
Search for code: "!dataframe"
Apply a tag filter: "#python"
Useful Shortcuts
/ to open search panel
Esc to close search panel
to navigate between search results
d to clear all current filters
Enter to expand content preview
Doc Search
Code Search Beta
SORRY NOTHING FOUND!
mic
Start speaking...
Voice search is only supported in Safari and Chrome.
Shrink
Navigate to

# NumPy | random method

schedule Aug 12, 2023
Last updated
local_offer
PythonNumPy
Tags
expand_more
mode_heat
Master the mathematics behind data science with 100+ top-tier guides
Start your free 7-days trial now!

NumPy's `random()` returns a random Float value between 0 (inclusive) and 1 (exclusive).

This method is equivalent to NumPy's `ranf()` and `random_sample()`.

NOTE

To generate random floats between a certain interval, use `uniform(~)` instead.

# Parameters

1. `size`link | `int` or `sequence` of `int` | `optional`

The desired number of random values to generate. By default, `size=1`.

# Return value

A NumPy array of random floats between 0 (inclusive) and 1 (exclusive). If `size` is not specified, a scalar is returned.

# Examples

## Generate 1D array of random numbers

To generate three random numbers:

``` np.random.random(3) array([0.66461748, 0.63058654, 0.48938284]) ```

## Generate 2D array of random numbers

To generate a 2 by 3 two-dimensional array of random numbers:

``` np.random.random([2,3]) array([[0.59041415, 0.19836836, 0.98704182], [0.41153823, 0.08973394, 0.72238062]]) ```
Edited by 0 others
thumb_up
thumb_down
Comment
Citation
Ask a question or leave a feedback...
thumb_up
0
thumb_down
0
chat_bubble_outline
0
settings
Enjoy our search
Hit / to insta-search docs and recipes!