Playable random values ​​in a vector of arbitrary length

I need to create a random number corresponding to each value in the index, where it should be reproducible for each value of the index, regardless of how many indexes are specified:

As an example, I could provide indices from 1 to 10, and then at another time, call the indices from 5 to 10, and both of them should be the same for values ​​from 5 to 10. Setting the global seed will not do this, it will be saved the same for the nth element in a random call by position in a vector.

What I have so far works as desired:

f = function(ix,min=0,max=1,seed=1){
  sapply(ix,function(x){
    set.seed(seed + x)
    runif(1,min,max)
  })
}
identical(f(1:10)[5:10],f(5:10)) #TRUE
identical(f(1:5),f(5:1)) #FALSE
identical(f(1:5),rev(f(5:1))) #TRUE

I was wondering if there is a more efficient way to achieve the above, without explicitly defining a seed for each index, as an offset to a global seed.

+4
1

. . , ; cyphertext. DES 64- AES 128- . Feistel (, ) Hasty Pudding.

0

Source: https://habr.com/ru/post/1664867/


All Articles