cas_rand: Generate random validly formatted CAS RNs

View source: R/cas_rand.R

cas_randR Documentation

Generate random validly formatted CAS RNs

Description

Make random CAS RNs of valid length format, without checksum consideration

Usage

cas_rand(n)

Arguments

n

integer. How many random CAS RNs do you wish to generate? numeric or character input will be coerced to integer, if possible. Negative (valid) input will be transformed to positive via abs

Details

Generate n random CAS RNs with valid CAS digit length (per section and overall). Random applies to all three sections of a CAS RN; for the first section, lengths will also be of random length, between 2:7.

This function does not perform any additional validation, which means duplicate CAS are possible. More importantly, there is no last (checksum) digit validation.

Value

A vector of random CAS RNs of length n.

Note

This is mainly useful as a testing tool for cas_checkSum. See examples.

Examples

set.seed(1)
random_CASRN <- cas_rand(1E4L)
length(unique(random_CASRN))
table(nchar(random_CASRN)-2) #-2 for two dashes
#using cas_detect and cas_checkSum
table(cas_detect(unique(random_CASRN)))
table(cas_checkSum(unique(random_CASRN)))

slin30/wzMisc documentation built on Jan. 27, 2023, 1 a.m.