Skip to contents

A function that generates random Finnish personal identity codes (hetu codes).

Usage

rpin(
  n,
  start.date = as.Date("1895-01-01"),
  end.date = Sys.Date(),
  p.male = 0.4,
  p.temp = 0,
  num.cores = 1
)

rhetu(
  n,
  start.date = as.Date("1895-01-01"),
  end.date = Sys.Date(),
  p.male = 0.4,
  p.temp = 0,
  num.cores = 1
)

Arguments

n

number of generated hetu-pins

start.date

Lower limit of generated hetu dates, character string in ISO 8601 standard, for example "2001-02-03". Default is "1895-01-01".

end.date

Upper limit of generated hetu. Default is current date.

p.male

Probability of males, between 0.0 and 1.0. Default is 0.4.

p.temp

Probability of temporary identification numbers, between 0.0 and 1.0. Default is 0.0.

num.cores

The number of cores for parallel processing. The number of available cores can be determined with detectCores(). Default is 1.

Value

a vector of generated hetu-pins.

Details

There is a finite number of valid personal identity codes available per day. More specifically, there are 498 odd personal numbers for males and 498 even personal numbers for females from range 002-899. Additionally there are 50 odd numbers for males and 50 even numbers for females in the temporary personal identity code number range 900-999 that is not normally in use. This function will return an error "too few positive probabilities" in sample.int function if you try to generate too many codes in a short enough timeframe.

The theoretical upper limit of valid PINs is in the millions since there are 898 PINs available for each day, 327770 for each year. In practice this number is much lower since same personal number component cannot be "recycled" if it has been used in the past. To illustrate, if an identity code "010101-0101" has already been assigned to someone born in 1901-01-01, a similar code "010101A0101" for someone born in 2001-01-01 could not be used.

Author

Pyry Kantanen, Jussi Paananen

Examples

x <- rpin(3)
hetu(x)
#>          hetu    sex p.num ctrl.char       date day month year century
#> 1 140142-403N   Male   403         N 1942-01-14  14     1 1942       -
#> 2 080155-327P   Male   327         P 1955-01-08   8     1 1955       -
#> 3 080609A882S Female   882         S 2009-06-08   8     6 2009       A
#>   valid.pin
#> 1      TRUE
#> 2      TRUE
#> 3      TRUE
hetu(x, extract = "sex")
#> [1] "Male"   "Male"   "Female"
hetu(x, extract = "ctrl.char")
#> [1] "N" "P" "S"

x <- rhetu(3)
x
#> [1] "220895+2164" "090212-806H" "230167-818A"