Very simply, I am trying to create a list of random numbers from 1:7 without replacement (it is to decide who selects 1st through 7th in a game of 7 players).
Using the code below (in R Console), the sequence seems random enough.
sample(seq(from=1, to=7, by=1), size=7, replace=F) [1] 1 6 5 3 7 4 2
re-running the code a number of times generates the following results.
[1] 7 6 2 1 3 5 4 [1] 1 2 7 3 6 5 4 [1] 5 1 4 6 2 7 3 [1] 6 5 4 7 2 1 3
Checking that they are random, using R on its own generates exactly the same sequences of 7 numbers, in the same order. Closing and restarting either R interface and re-running the same simple code again produces the same sequences of 7 numbers. Using the following, simpler code, also gives the same results:
sample(1:7, 7, replace=F)
It would seem, then, that the "sample" command is not generating a random sample, but a predetermined one - which means I must be doing something wrong. As a newbie to R, I can't figure out what, nor have I been able to locate a similar question and answer here on StackOverflow (though that doesn't mean there isn't one...).
Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire