From 0e88a4af4b702572b5567aa81f77ea16286b50dd Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 8 Oct 2025 14:05:11 +0530 Subject: [PATCH 1/5] created the required randint.md file --- .../random-module/terms/randint/randint.md | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 content/numpy/concepts/random-module/terms/randint/randint.md diff --git a/content/numpy/concepts/random-module/terms/randint/randint.md b/content/numpy/concepts/random-module/terms/randint/randint.md new file mode 100644 index 00000000000..2469916ec36 --- /dev/null +++ b/content/numpy/concepts/random-module/terms/randint/randint.md @@ -0,0 +1,85 @@ +--- +Title: 'randint' +Description: 'Generates random integers from a specified range in NumPy.' +Subjects: + - 'Computer Science' + - 'Data Science' +Tags: + - 'Numpy' + - 'Python' + - 'Random' +CatalogContent: + - 'learn-python-3' + - 'paths/computer-science' +--- + +**`randint()`** is a function from NumPy's `random` module that generates random integers. It can generate a single integer or an array of integers within a specified range, making it useful for simulations, testing, and randomized operations. + +## Syntax + +```python +numpy.random.randint(low, high=None, size=None, dtype=int) +``` + +**Parameters:** + +- `low` (int): Lowest integer to be drawn (inclusive). +- `high` (int, optional): If provided, the largest integer (exclusive). If `None`, the range is `0` to `low - 1`. +- `size` (int or tuple of ints, optional): Output shape. If `None`, a single integer is returned. +- `dtype` (data-type, optional): Desired data type of the output. Default is `int`. + +**Return value:** + +- `out` (int or ndarray): Random integer(s) from the specified range. + - If `size` is `None`, returns a single integer. + - If `size` is specified, returns a NumPy array of the given shape. + +## Example + +This example demonstrates generating random integers: + +```py +import numpy as np +np.random.seed(15) + +# Single random integer from 0 to 9 +single_int = np.random.randint(10) +print(single_int) + +# Array of 5 random integers from 1 to 5 +arr = np.random.randint(1, 6, size=5) +print(arr) +``` +The output for this code will be: + +```shell +3 +[5 2 2 1 2] +``` + +Here: + +- `np.random.seed(15)` ensures reproducible results. +- `np.random.randint(10)` generates a single integer between 0 and 9. +- `np.random.randint(1, 6, size=5)` generates an array of 5 integers between 1 and 5. + + +## Codebyte Example + +This codebyte sample generates a single random integer and a 2×3 array of random integers from specified ranges, ensuring reproducible results using a fixed random seed. + +```codebyte/python +import numpy as np +np.random.seed(42) + +# Single random integer between 0 and 9 +num = np.random.randint(10) +print(f"Random integer: {num}") + +# 2x3 array of random integers between 1 and 10 +arr = np.random.randint(1, 11, size=(2, 3)) +print(f"Random integers array:\n{arr}") +``` + +- `np.random.seed(42)` ensures the code produces the same results every time. +- `size=(2, 3)` generates a 2D array with 2 rows and 3 columns of random integers. \ No newline at end of file From c11149a5ea18b460791c6f378d664a2bfc57a530 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 8 Oct 2025 14:26:45 +0530 Subject: [PATCH 2/5] yarn format --- content/numpy/concepts/random-module/terms/randint/randint.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/numpy/concepts/random-module/terms/randint/randint.md b/content/numpy/concepts/random-module/terms/randint/randint.md index 2469916ec36..d53e9ed07a1 100644 --- a/content/numpy/concepts/random-module/terms/randint/randint.md +++ b/content/numpy/concepts/random-module/terms/randint/randint.md @@ -50,6 +50,7 @@ print(single_int) arr = np.random.randint(1, 6, size=5) print(arr) ``` + The output for this code will be: ```shell @@ -63,7 +64,6 @@ Here: - `np.random.randint(10)` generates a single integer between 0 and 9. - `np.random.randint(1, 6, size=5)` generates an array of 5 integers between 1 and 5. - ## Codebyte Example This codebyte sample generates a single random integer and a 2×3 array of random integers from specified ranges, ensuring reproducible results using a fixed random seed. @@ -82,4 +82,4 @@ print(f"Random integers array:\n{arr}") ``` - `np.random.seed(42)` ensures the code produces the same results every time. -- `size=(2, 3)` generates a 2D array with 2 rows and 3 columns of random integers. \ No newline at end of file +- `size=(2, 3)` generates a 2D array with 2 rows and 3 columns of random integers. From 1fef8d57c516f74bffa5351581938e96471c19c1 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Wed, 8 Oct 2025 18:27:05 +0530 Subject: [PATCH 3/5] minor fix --- .../concepts/random-module/terms/randint/randint.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/content/numpy/concepts/random-module/terms/randint/randint.md b/content/numpy/concepts/random-module/terms/randint/randint.md index d53e9ed07a1..eb00316d36c 100644 --- a/content/numpy/concepts/random-module/terms/randint/randint.md +++ b/content/numpy/concepts/random-module/terms/randint/randint.md @@ -1,6 +1,6 @@ --- -Title: 'randint' -Description: 'Generates random integers from a specified range in NumPy.' +Title: 'randint()' +Description: 'Generates random integers within a specified range using NumPy.' Subjects: - 'Computer Science' - 'Data Science' @@ -17,14 +17,14 @@ CatalogContent: ## Syntax -```python +```pseudo numpy.random.randint(low, high=None, size=None, dtype=int) ``` **Parameters:** -- `low` (int): Lowest integer to be drawn (inclusive). -- `high` (int, optional): If provided, the largest integer (exclusive). If `None`, the range is `0` to `low - 1`. +- `low` (int): Lowest (inclusive) integer to be drawn. +- `high` (int, optional): One above the highest integer to be drawn. If not provided, integers are drawn from the range `[0, low)`. - `size` (int or tuple of ints, optional): Output shape. If `None`, a single integer is returned. - `dtype` (data-type, optional): Desired data type of the output. Default is `int`. @@ -66,7 +66,7 @@ Here: ## Codebyte Example -This codebyte sample generates a single random integer and a 2×3 array of random integers from specified ranges, ensuring reproducible results using a fixed random seed. +This codebyte sample generates a single random integer and a 2×3 array of random integers from specified ranges, ensuring reproducible results using a fixed random seed: ```codebyte/python import numpy as np From 9f0a7d64319a9513920dc29096cd8d3225c20bdd Mon Sep 17 00:00:00 2001 From: Dhruv Date: Thu, 9 Oct 2025 20:33:46 +0530 Subject: [PATCH 4/5] created b2a-base16.md --- .../terms/b2a-base16/b2a-base16.md | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 content/python/concepts/binascii-module/terms/b2a-base16/b2a-base16.md diff --git a/content/python/concepts/binascii-module/terms/b2a-base16/b2a-base16.md b/content/python/concepts/binascii-module/terms/b2a-base16/b2a-base16.md new file mode 100644 index 00000000000..e3aec20e6ec --- /dev/null +++ b/content/python/concepts/binascii-module/terms/b2a-base16/b2a-base16.md @@ -0,0 +1,65 @@ +--- +Title: '.b2a_base16()' +Description: 'Converts binary data into a bytes object containing a hexadecimal (Base16) ASCII representation.' +Subjects: + - 'Computer Science' + - 'Data Science' +Tags: + - 'Encoding' + - 'Functions' + - 'Hexadecimal' +CatalogContent: + - 'learn-python-3' + - 'paths/computer-science' +--- + +The **`.b2a_base16()`** [function](https://docs.python.org/3/library/binascii.html#binascii.b2a_base16) converts binary data into a bytes object containing a string of ASCII characters representing the data in Base16 (hexadecimal) format. + +## Syntax + +```pseudo +binascii.b2a_base16(data, *, newline=False) +``` + +- `data`: A bytes object containing the binary data to be encoded. +- `*`: This indicates that any arguments following it must be passed using keyword syntax. +- `newline`: When set to True, a newline (`\n`) is appended to the encoded output. Default is False. + +## Example + +```py +import binascii + +# Create binary data to encode +binary_data = b"hello" + +# Encode the binary data to Base16 ASCII format +encoded_data = binascii.b2a_base16(binary_data) + +print(encoded_data) +``` + +This produces the following output: + +```shell +b'68656C6C6F' +``` + +> **Note** : Each byte of the input is converted to its two-character hexadecimal representation. + +## Codebyte Example + +```codebyte/python +import binascii + +binary_data = b"Codecademy" +encoded_data = binascii.b2a_base16(binary_data) + +print(encoded_data) +``` + +This produces: + +```shell +b'436F6465636164656D79' +``` From c1a200a2f9ff80dc1d4b7cadb8db8c9e54cfe669 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Thu, 9 Oct 2025 21:23:19 +0530 Subject: [PATCH 5/5] some changes