Random Number Generator with Random Package

Random number generator, Real random numbers cannot be decrypted with a random seed, unlike pseudo-random numbers, which may be better in terms of security and hacker protection.

True random values are also closer to nature, which may make them more suitable for random experiments and simulation research.

Linear Discriminant Analysis in R » LDA Prediction » finnstats

In order to use the random package’s functionality, we must first install and load the package:

#install.packages("random")            
library("random")

Approach 1: Make a data set with duplicates of random integers.

We’ll show you how to make a random data set with random integers in the first example.

We can utilize the randomNumbers function from the random package for this assignment.

Subscribe to our newsletter!

[newsletter_form type=”minimal”]

We can specify numerous arguments within this function, including the sample size, the lowest value, the maximum value, and the number of columns.

Introduction to Recurrent Neural Networks (RNN) » finnstats

Take a look at the code below for an example

Random Number Generator

df1 <- randomNumbers(n = 30,min = 0,max = 5000,col = 5)
df1
       V1   V2   V3   V4   V5
[1,] 1429 4332 1642 2979 4696
[2,] 1829  537 4143 2690 3971
[3,] 3611 4532 4895 1486 2438
[4,] 1470 3733 4908  313 1378
[5,] 2658 4105 1673 2701  502
[6,] 3314 4369 4016 3210 4777

It shows the six rows of our random data. We’ve constructed a data collection with five columns and six rows, as you can see.

It’s worth noting that our data’s integer values might be duplicated. In the next example, We’ll show you how to make a data set with only one value per row.

Experimental Design in Research | Quick Guide » finnstats

Approach 2: Create a data set with a random sequence and no duplicates.

df2 <- randomSequence(min = 5,max = 10,col = 2)
df2
    V1 V2
[1,] 7 8
[2,] 6 10
[3,] 9 5

We’ve built a data set with three rows and two variables, as you can see from the data frame above. Each value only appears once.

Approach 3: Create a vector of randomly generated character strings of a specific length.

vec<- as.vector(randomStrings(n = 100,  len = 3)) vec     

Here is the output…                              

[1] "mGT" "FGk" "GNK" "jFB" "oSt" "sR4" "UKx" "TS5" "y2k" "RrB" "YKz" "kU0" "Nym" "jS5" "wM3"
 [16] "Izc" "slB" "NHa" "aqR" "MZb" "h1R" "KoZ" "oKB" "1OJ" "1e0" "4mr" "zHK" "uuo" "OB9" "gxU"
 [31] "5mc" "PVa" "mdy" "azd" "juh" "IIL" "gsv" "3CX" "AeT" "6v9" "pyv" "5rj" "MhO" "4tD" "SUs"
 [46] "ADe" "zqu" "GPk" "6Hd" "iZs" "9nP" "mgS" "In8" "Vr9" "hUu" "52H" "XtP" "MLy" "YJg" "RV3"
 [61] "bNi" "4Vk" "hSa" "KUG" "ouZ" "4GB" "hjh" "Vn8" "fR0" "qGy" "MI6" "hzM" "9Cs" "9fk" "gea"
 [76] "1z8" "tQr" "ihC" "CZ1" "QYC" "m7t" "dAG" "qtj" "cUx" "feL" "zlV" "uJP" "L42" "1l4" "nfo"
 [91] "0GU" "ban" "Yta" "PeM" "4Cs" "tm4" "iCV" "m1Y" "oek" "Ban"

X bar R Chart Relation in Quality Control » finnstats

In the preceding R code, a character string vector with 100 vector elements was simulated. Each of these items has a three-character random character string.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

20 − 8 =