小编ywx*_*ywx的帖子

如何使用 c++uniform_int_distribution 在不替换的情况下进行采样

我想在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)

c++ random

6
推荐指数
2
解决办法
6682
查看次数

R中函数对象的区别

假设我在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)

r

1
推荐指数
1
解决办法
314
查看次数

标签 统计

c++ ×1

r ×1

random ×1