草庐IT

random_hash

全部标签

javascript - 如何向元素添加#hash clicking

当我在http://www.mywebsite.com/打开我的页面时我有这个jQuery代码的地方:$('#locSlideButton2').click(function(){});我想单击locSlideButton2元素,向url添加哈希(例如#example),而不进行任何重定向。我该怎么做? 最佳答案 使用普通的旧VanillaJS:window.location.hash='example';MDNonwindow.location 关于javascript-如何向元素添加

javascript - 跨浏览器随机字符串 (Math.random()*1e32).toString(36)

我使用(Math.random()*1e32).toString(36)作为一个简单的随机字符串生成器。它非常简单并且运行良好并满足我的需求(临时随机用于id等)在chrome、safari、firefox和ieMath.random()*1e32中生成如下数字:8.357963780872523e+31:-)在chrome、safari和firefox中,此类数字被转换为字符串(8.357963780872523e+31).toString(36)->221fr2y11ebk4cog84wok这正是我想要的。但是在ie11中,字符串结果是6.936gwtrpf69(e+20)。如何以

c++ - 为什么 {} 用于访问 std::hash 中的 operator()?

在阅读用于std::unordered_map的std::hash示例时,我注意到{}正在访问operator()函数。http://en.cppreference.com/w/cpp/utility/hashresult_typeoperator()(argument_typeconst&s)const{result_typeconsth1(std::hash{}(s.first_name));result_typeconsth2(std::hash{}(s.last_name));returnh1^(h2这里使用{}代表什么? 最佳答案

c++ - hash_map 有多普遍?

hash_map和hash_setheader尚未包含在C++标准中,但它们可作为我最近使用的所有编译器的扩展使用。我想知道在不牺牲可移植性的情况下,在实际代码中我可以在多大程度上依赖这些。我正在从事需要在许多架构和编译器上运行的工具项目,包括:Linux(x86_64、AMD/Intel):GCC、Intel、Portland编译器AIX(强大):GCC、xlCCrayXT系列(AMD):GCC、Portland、Pathscale编译器IBM蓝色基因系列(电源):xlC、GCCSGIAltix(Itanium):Intel编译器Windows:不是真正的优先事项,但随时提供有用的答

c++ - std::hash 模板特化的前向声明

为什么前向声明如下:templatestructstd::hash;用gcc和clang编译失败,但用VisualStudio2015编译?gcc6.1.0(使用coliru):main.cpp:11:34:error:invaliduseoftemplate-name'std::hash'withoutanargumentlisttemplatestructstd::hash;^~~~clang3.8.0(使用coliru):main.cpp:11:29:error:forwarddeclarationofstructcannothaveanestednamespecifiertem

c++ - 定义 std::hash<std::function>

我需要创建一个模板类,它可以保存指向T类型元素的指针。然后对它们执行功能。这些函数会来自不同的地方,所以我需要一个容器来存储它们,以便以后调用它们。我决定使用std::unordered_set,因为它提供了速度并限制了重复,因为它被实现为哈希表。我编写了整个类,但由于没有为我的std::function定义的散列函数,所以无法编译。它采用T类型的指针并返回void.用struct hash>指定它很容易(并且还重载了()运算符)对于我使用的每种类型,但我实际上如何对函数进行哈希处理?这是我的类(class)中相关成员和方法的精简摘录:templateclassMaster{priva

c++ - 在这种特殊情况下,为什么不需要将 std::hash() 的特化注入(inject)到 std namespace 中?

考虑usingnamespacestd;templatestructhash>{inlinesize_toperator()(constpair&v)const{return0;}};在这种情况下,GCC和Clang都可以正常编译,没有任何警告。然而,这似乎与我在网上读到的内容相矛盾,即定义您自己的哈希函数以与标准库的无序类型一起使用需要您将定义放在std命名空间中。有趣的是,专门针对pair:templatestructhash>{size_toperator()(constpair&v)const{size_tseed=0;returnseed;}};如我们所料导致错误。但是,为什

c++ - boost::uuids::random_generator 线程安全吗?

考虑使用g++-std=c++11(GCC4.7.2)编译的函数:boost::uuids::uuidgetID(){staticboost::uuids::random_generatorgenerator;returngenerator();}从多个线程调用getID是否安全?如前所述here根据C++11标准,第一行的局部静态对象定义是线程安全的。问题是在第二行对同一对象generator调用boost::uuids::random_generator::operator()是否也是线程安全的。返回的UUID在单个线程中是否是唯一的? 最佳答案

c++ - 如何测试 std::random_device 的随机性?

假设我有这个跨平台程序#include#includeintmain(){std::random_devicerd;std::coutdist(0,9);for(inti=0;i在带有g++(Ubuntu4.8.2-19ubuntu1)4.8.2的LinuxMint17.1上,它总是产生随机数:$g++-std=c++11testrd.cpp-otestrd$./testrdrd.entropy=09260810238$./testrdrd.entropy=03624118375$./testrdrd.entropy=03446854663$./testrdrd.entropy=024

c++ - 在 Visual Studio 下使用 pair 作为 hash_map 的键

尝试在VisualStudio2010下使用pair作为hash_map的键值。无法编译。int_tmain(intargc,_TCHAR*argv[]){hash_map,int>months;months[pair(2,3)]=1;intd;cin>>d;return0;}收到错误信息:Error1errorC2440:'typecast':cannotconvertfrom'conststd::pair'to'size_t'c:\programfiles\microsoftvisualstudio10.0\vc\include\xhash341testApplication1我知