randomnumGenerator: Random number generator

Description Usage Arguments Value Author(s) References Examples

View source: R/randomnumGenerator.R

Description

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

Usage

1
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

An array of different random numbers

Author(s)

Sebnem Er

References

Swap method of Charlie Daly

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
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])
   
   }

GA4Stratification documentation built on May 30, 2017, 1:22 a.m.