Following are the key points described later in this article:
“Runif” command can be used for generating random numbers based on uniform distribution. One can generate one or more random numbers within a range of numbers. One should note that the random numbers generated using runif commands are all decimal (non-integers) numbers.
# Generate 5 random numbers
runif(5)
# Generate 5 random numbers (Non-integers) between 2 and 7
runif(5, 2, 7)
“Sample” command is also used for generating random numbers based on uniform distribution. One can generate one or more random numbers within a range of numbers. One should note that the random numbers generated using runif commands are all integer numbers. This is the key difference between runif and sample command.
# Generate 5 random numbers (Integers)
sample(5)
# Generate 5 random numbers (Integers) between 2 and 7; Duplicates are allowed
# with replace parameter set to True (T)
sample(2:7, 5, replace=T)
# Generate 5 random numbers (Integers) between 2 and 7; Duplicates are NOT allowed
# with replace parameter set to False (F)
sample(2:7, 5, replace=F)
# Generate 5 country names from the vector countryNames with replace as false
countryNames <- c("India","USA","Pakistan","China","Japan","South Korea","Mangolia")
sample(countryNames, 5)
“Rnorm” command is used for generating random numbers based on normal distribution.
# Generate 5 random numbers with mean as 0 and standard deviation as 1
rnorm(5)
# Generate 5 random numbers with mean as 5 and standard deviation as 2
rnorm(500, mean=5, sd=2)
The key difference between runif/sample and rnorm command is following:
Last updated: 25th Jan, 2025 Have you ever wondered how to seamlessly integrate the vast…
Hey there! As I venture into building agentic MEAN apps with LangChain.js, I wanted to…
Software-as-a-Service (SaaS) providers have long relied on traditional chatbot solutions like AWS Lex and Google…
Retrieval-Augmented Generation (RAG) is an innovative generative AI method that combines retrieval-based search with large…
The combination of Retrieval-Augmented Generation (RAG) and powerful language models enables the development of sophisticated…
Have you ever wondered how to use OpenAI APIs to create custom chatbots? With advancements…