Learn R Programming

GA4Stratification (version 1.0)

randomnumGenerator: Random number generator

Description

This function generates random variables that don't repeat in a given range

Usage

randomnumGenerator(randomnumRange, lengthRandomnum, howManyRands)

Arguments

randomnumRange
This is the range of the random numbers

randomnumRange can be something given as: randomnumRange=1:487

or

randomnumRange=c(6, 12, 36, 67, 87, 146, 267)

therefore length of the randonnumRange

in the first case is 487

in the second case is 7, defining the index of the randomnumRange to be swapped

lengthRandomnum
This is the length of the random number range
howManyRands
Number of random values

Value

References

Swap method of Charlie Daly

Examples

Run this code
randomnumGenerator(c(1,3,5,7,9,15,21),7,3)

function(randomnumRange,lengthRandomnum,howManyRands)
   {

  	for (i in 1:(howManyRands))
   	{
		integer=sample(lengthRandomnum-1,1)
		tmp=randomnumRange[integer]
		randomnumRange[integer]=randomnumRange[i]
		randomnumRange[i]=tmp
   	}
	return(randomnumRange[1:howManyRands])
   
   }

Run the code above in your browser using DataLab