我有一个要在页面刷新时随机生成的数组

时间:2019-03-09 03:55:35

标签: php

我有一个数组示例:

// let's assume we don't have any headphones connected
let headphonesConnected = false;

const updateDevices = () => {
  navigator.mediaDevices.enumerateDevices()
    .then(function(devices) {
      // check to see if we have any device with "head" in its name connected
      // like "headset" or "headphones"
      headphonesConnected = devices
        .filter(device => /audio\w+/.test(device.kind))
        .find(device => device.label.toLowerCase().includes('head'))
      ;
    })
  ;
};

updateDevices();

// add an ondevicechange event listener so we can tell when
// an input device is connected and disconnected
navigator.mediaDevices.ondevicechange = updateDevices;

当我引用我的页面时,我想要这样的结果。

第一次推荐

ondevicechange

第二次刷新

Array
(
[0] => 5c832a3fec3a6
[1] => 5c832a3fdbe90
[2] => 5c832a3fc6335
[3] => 5c832a3fb080d
[4] => 5c832a3f89d5b
)

这意味着每次出现新的随机数组。

1 个答案:

答案 0 :(得分:-1)

作为shuffle()的替代方法,您也可以使用rand()

#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
double MyCppFunction(NumericVector x, NumericVector y) {
  return (sum(x) + sum(y));
}

注意事项

这是一项代价高昂的练习,因此,对于像这样的小型数组而言,它相对而言是无害的,但我可能会坚持使用shuffle()