char2seed           package:TeachingDemos           R Documentation

_C_o_n_v_e_r_t _a _c_h_a_r_a_c_t_e_r _s_t_r_i_n_g _i_n_t_o _a _r_a_n_d_o_m _s_e_e_d

_D_e_s_c_r_i_p_t_i_o_n:

     This function creates a seed for the random number generator from
     a character string.  Character strings can be based on student
     names so that every student has a different random sample, but the
     teacher can generate the same datasets.

_U_s_a_g_e:

     char2seed(x, set = TRUE, ...)

_A_r_g_u_m_e_n_t_s:

       x: A character string 

     set: Logical, should the seed be set or just returned 

     ...: Additional parameters passed on to 'set.seed' 

_D_e_t_a_i_l_s:

     Simulations or other situations call for the need to have
     repeatable random numbers, it is easier to remember a word or
     string than a number, so this function converts words or character
     strings to an integer and optionally sets the seed based on this.

     Teachers can assign students to generate a random dataset using
     their name to seed the rng, this way each student will have a
     different dataset, but the teacher can generate the same set of
     data to check values.

     Any characters other than letters (a-zA-Z) or digits (0-9) will be
     silently removed.  This function is not case sensitive, so "ABC"
     and "abc" will generate the same seed.

     This is a many to one function, so it is possible to find
     different words that generate the same seed, but this is unlikely
     by chance alone.

_V_a_l_u_e:

     This returns an integer (but mode numeric) to use as a seed for
     the RNG.  If 'set' is true then it is returned invisibly.

_A_u_t_h_o_r(_s):

     Greg Snow greg.snow@intermountainmail.org

_S_e_e _A_l_s_o:

     'set.seed'

_E_x_a_m_p_l_e_s:

     char2seed('Snow')
     x <- rnorm(100)
     rnorm(10)
     tmp <- char2seed('Snow',set=FALSE)
     set.seed(tmp)
     y <- rnorm(100)

     all.equal(x,y) # should be true

