我想在c++随机库中使用uniform_int_distribution。但是,它只进行有替换的采样,如下例所示。如何在不更换的情况下进行采样?
#include <iostream>
#include <random>
int main()
{
std::default_random_engine generator;
std::uniform_int_distribution<int> distribution(1,4);
for(int i=0; i<4; ++i)
std::cout << distribution(generator) << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud) 假设我在R工作区中创建了一个函数列表,同一组函数也在R文件中,之后source(),源函数对象应该与我创建的列表中的相应函数相同,但事实并非如此.
例:
fR文件包含 f <- function(x) x^2.
在R控制台:
lst <- list(f=function(x) x^2)
source("f.R")
> ls()
[1] "f" "lst"
> identical(f,lst$f)
[1] FALSE
> str(f)
function (x)
- attr(*, "srcref")=Class 'srcref' atomic [1:8] 1 6 1 20 6 20 1 1
.. ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' <environment: 0x1b2fd60>
> str(lst$f)
function (x)
- attr(*, "srcref")=Class 'srcref' atomic [1:8] 1 16 1 30 16 30 1 1
.. ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' <environment: 0x1bb4b50>
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
> identical(f,lst$f, …Run Code Online (Sandbox Code Playgroud)