char2seed: Convert a character vector to a numeric integer for setting a...

Description Usage Arguments Details Value Author(s) Examples

View source: R/char2seed.R

Description

char2seed() is a parlor trick for converting a character vector into an integer for the sake of setting a reproducible seed.

Usage

1
2
3

Arguments

x

a character vector

Details

Interested users can see how this works. Namely, letters (and numbers) in the character vector are assigned corresponding numbers. In char2seed(), these numbers are concatenated together an divided over 1 minus the absolute maximum number that R can handle by default (2^32). The remainder of this division is what ultimately becomes the reproducible seed.

In char2seed_v1(), these numbers are added together and then exponentiated to create a really big number. The number is divided over 1 minus the absolute maximum number that R can handle by default (2^32). The remainder of this division is what ultimately becomes the reproducible seed.

The nature of this parlor trick means there's a possibility, however small, that two different character vectors can return the same reproducible seed. This happened before https://github.com/svmiller/codename/issues/1, which is why I changed the function for generating the seed and moved the old function to char2seed_v1().

The function may warn of "loss of accuracy", but this just means you supplied it a really long character vector.

Value

char2seed() takes a character vector and returns a reproducible seed for you to use for whatever purpose. It's used internally in codename(). char2seed_v1() does the same, but using the older method from v. 0.1.0 and v. 0.2.0 of this release.

Author(s)

Steven V. Miller

Examples

1
2
3
char2seed("ABCDEF")
char2seed("Go Bucks!")
char2seed("My Project Title")

codename documentation built on Sept. 8, 2021, 1:08 a.m.