Generate Random Numbers in Python

Vikram Chiluka
Updated on 23-Apr-2025 17:07:49

784 Views

Python includes a built-in package i.e random module for generating random numbers. In this article, we will show you how to generate random numbers in python using different methods - Using random.seed() Method Using random.randrange() Method Using random.randint() Method ... Read More

C++ Program to Implement Fermat's Little Theorem

Ravi Ranjan
Updated on 23-Apr-2025 17:07:46

1K+ Views

Fermat's Little Theorem states that if p is a prime number and a is an integer not divisible by p, then a^(p-1) is congruent to 1 modulo p. It can be represented as a(p-1) ≡ 1 (mod p). It can also be said that if any integer a is raised to the (p-1) where p is a prime and gcd(a, p) =1, then a^(p-1)-1 is divisible by p. In this article, we have two integers i.e. 'a' and a prime number 'p' such that a is not divisible by p. Our task is to implement Fermat's Little theorem using these ... Read More

Implement Park-Miller Random Number Generation Algorithm in C++

Ravi Ranjan
Updated on 23-Apr-2025 17:02:49

663 Views

The Park-Miller algorithm is a type of linear congruential generator (LCG) that is used to generate pseudo-random numbers. It is also called the minimal standard random number generator. The general formula of a random number generator (RNG) of this type is: X_{k+1} = g X(k) mod n where the modulus n is a prime number or a power of a prime number, the multiplier g is an element of high multiplicative order modulo n, and the seed X0 is co-prime to n. In this article, we will be using Park-Miller algorithm to generate 5 pseudo-random numbers using C++. Here is ... Read More

Match at the End of String in Python Using Regular Expression

Pranav Indukuri
Updated on 23-Apr-2025 16:00:05

15K+ Views

A regular expression in Python is a set of characters that allows you to use a search pattern to find a string or a group of strings. These are used within Python using the re package. To match the end of the string in Python by using a regular expression, we use the following regular expression -^/w+$ Here, $ implies the start with. /w returns a match where ... Read More

Match Non-Digit Characters in Python Using Regular Expression

Pranav Indukuri
Updated on 23-Apr-2025 15:55:15

6K+ Views

A regular expression is a group of characters that allows you to use a search pattern to find a string or a set of strings. RegEx is another name for regular expressions. The re module in Python is used to work with regular expressions. In this article, we learn how to extract non-digit characters in Python using regular expressions. We use \D+ regular expression in Python to get non-digit characters from a string. Where, \D returns a match that does not contain digits. + implies zero or more occurrences of characters. ... Read More

Match Any One Uppercase Character in Python Using Regular Expression

Nikitasha Shrivastava
Updated on 23-Apr-2025 14:49:17

2K+ Views

There are two ways to match any one uppercase character in python using Regular Expression. One is the general method and other is using the regular expression. A regular expression is a series of characters that allows you to discover a string or a set of strings using a search pattern. Regular expressions are sometimes known as RegEx. In Python, the re module is used to work with regular expressions. How to Match an Uppercase Character? In this article we will match the uppercase vowel in Python using a regular expression. To do this we will use r'[A, E, I, ... Read More

Differences Between Untyped and Dynamically Typed Programming Languages

Nikitasha Shrivastava
Updated on 23-Apr-2025 14:42:23

2K+ Views

When learning different programming languages, you may come across terms like untyped and dynamically typed. While they may sound similar but they have different concepts in how programming languages manage data types. In this article, we will see these concepts in simple terms with simple examples. Untyped Language Untyped programming languages do not have a strict definition of data types. This allows you to use values without providing the data type. The interpreter or execution environment will handle everything anyway it considers a match. Example Let us look at an example that uses an untyped language - # ... Read More

Why Python Can't Define Tuples in a Function

Nikitasha Shrivastava
Updated on 23-Apr-2025 14:33:50

376 Views

In Python tuples are an important data structure that allows you to group many values together. But some beginners may find it confusing to use tuples inside functions. This article will explain what tuples are and how to use them properly in functions. We will also discuss some real-world examples, from basic to complex, to help you understand. A tuple is an ordered, unchangeable collection of datatypes in Python. It means that after a tuple has been created, its values cannot be changed. Tuples are defined with parentheses "()". Example of a Tuple Here is a simple example of how ... Read More

Assign Value to Multiple Variables Simultaneously in Python

Pranav Indukuri
Updated on 23-Apr-2025 13:10:49

7K+ Views

Python is not a "statically typed" programming language. We do not need to define variables or their types before utilizing them. Once we initially assign a value to a variable, it is said to be created. Each variable is assigned with a memory location. The assignment operator (=) assigns the value provided to right to the variable name which is at its left. The syntax of the assignment operator is shown below - var_name = value Example of Assignment Operator The following is an example that shows the usage of the assignment operator - Name = 'Tutorialspoint' In ... Read More

Check If a List is Empty in Python

Vikram Chiluka
Updated on 23-Apr-2025 12:58:39

57K+ Views

In Python, a list is an ordered sequence that can hold several object types, such as integers, characters, or floats. In this article, we will show you how to check if the given input list is empty or NOT using Python. Below are the 5 methods to accomplish this task - Using not operator Using len() function By Comparing with an Empty List Using __len__() Method Using NumPy Module Assume we have taken an empty list. We will check if the input list is empty or not and return some random message for acknowledgment using different methods as ... Read More

Advertisements