random

Generate N quasi random numbers in less than O(N)

♀尐吖头ヾ 提交于 2020-01-06 03:07:02
问题 This was inspired by a question at a job interview: how do you efficiently generate N unique random numbers? Their security and distribution/bias don't matter. I proposed a naive way of calling rand() N times and eliminating dupes by trial and error, thus getting inefficient and flawed solution. Then I've read this SO question, these algorithms are great for getting quality unique numbers and they are O(N). But I suspect there are ways to get low-quality unique random numbers for dummy tasks

random element from array in c

扶醉桌前 提交于 2020-01-06 02:24:08
问题 How can I select a random element from a character array in c ? For instance: char *array[19]; array[0] = "Hi"; array[1] = "Hello"; etc I am looking for something like array[rand], where rand is the random integer number between o and the array's length(in this case 20) like 1, 2, 3 , 19 etc. 回答1: To start things off, since you have an array of strings, not of characters, you have to declare it as char* array[19]; Then, you can declare the following (always useful) macro #define ARR_SIZE(arr)

randomly sum values from rows and assign them to 2 columns in R

天大地大妈咪最大 提交于 2020-01-06 01:59:09
问题 I have a data.frame with 8 columns. One is for the list of subjects (one row per subject) and the other 7 rows are a score of either 1 or 0. This is what the data looks like: >head(splitkscores) subject block3 block4 block5 block6 block7 block8 block9 1 40002 0 0 1 0 0 0 0 2 40002 0 0 1 0 0 1 1 3 40002 1 1 1 1 1 1 1 4 40002 1 1 0 0 0 1 0 5 40002 0 1 0 0 0 1 1 6 40002 0 1 1 0 1 1 1 I want to create a data.frame with 3 columns. One column for subjects. In the other two columns, one must have

转---写一个网页进度loading

偶尔善良 提交于 2020-01-06 01:48:37
作者:jack_lo www.jianshu.com/p/4c93f5bd9861 如有好文章投稿,请点击 → 这里了解详情 loading随处可见,比如一个app经常会有下拉刷新,上拉加载的功能,在刷新和加载的过程中为了让用户感知到 load 的过程,我们会使用一些过渡动画来表达。最常见的比如“转圈圈”,“省略号”等等。 网页loading有很多用处,比如页面的加载进度,数据的加载过程等等,数据的加载loading很好做,只需要在加载数据之前(before ajax)显示loading效果,在数据返回之后(ajax completed)结束loading效果,就可以了。 但是页面的加载进度,需要一点技巧。 页面加载进度一直以来都是一个常见而又晦涩的需求,常见是因为它在某些“重”网页(特别是网页游戏)的应用特别重要;晦涩是因为web的特性,各种零散资源决定它很难是“真实”的进度,只能是一种“假”的进度,至少在逻辑代码加载完成之前,我们都不能统计到进度,而逻辑代码自身的进度也无法统计。另外,我们不可能监控到所有资源的加载情况。 所以页面的加载进度都是“假”的,它存在的目的是为了提高用户体验,使用户不至于在打开页面之后长时间面对一片空白,导致用户流失。 既然是“假”的,我们就要做到“仿真”才有用。仿真是有意义的,事实上用户并不在乎某一刻你是不是真的加载到了百分之几

《动手实现一个网页加载进度loading》

时间秒杀一切 提交于 2020-01-06 01:48:18
loading随处可见,比如一个app经常会有下拉刷新,上拉加载的功能,在刷新和加载的过程中为了让用户感知到 load 的过程,我们会使用一些过渡动画来表达。最常见的比如“转圈圈”,“省略号”等等。 网页loading有很多用处,比如页面的加载进度,数据的加载过程等等,数据的加载loading很好做,只需要在加载数据之前(before ajax)显示loading效果,在数据返回之后(ajax completed)结束loading效果,就可以了。 但是页面的加载进度,需要一点技巧。 页面加载进度一直以来都是一个常见而又晦涩的需求,常见是因为它在某些“重”网页(特别是网页游戏)的应用特别重要;晦涩是因为web的特性,各种零散资源决定它很难是“真实”的进度,只能是一种“假”的进度,至少在逻辑代码加载完成之前,我们都不能统计到进度,而逻辑代码自身的进度也无法统计。另外,我们不可能监控到所有资源的加载情况。 所以页面的加载进度都是“假”的,它存在的目的是为了提高用户体验,使用户不至于在打开页面之后长时间面对一片空白,导致用户流失。 既然是“假”的,我们就要做到“仿真”才有用。仿真是有意义的,事实上用户并不在乎某一刻你是不是真的加载到了百分之几,他只关心你还要load多久。所以接下来我们就来实现一个页面加载进度loading。 首先准备一段loading的html: 1 <!DOCTYPE

写一个网页进度loading

女生的网名这么多〃 提交于 2020-01-06 01:48:02
转自: http://www.jianshu.com/p/4c93f5bd9861 loading随处可见,比如一个app经常会有下拉刷新,上拉加载的功能,在刷新和加载的过程中为了让用户感知到 load 的过程,我们会使用一些过渡动画来表达。最常见的比如“转圈圈”,“省略号”等等。 网页loading有很多用处,比如页面的加载进度,数据的加载过程等等,数据的加载loading很好做,只需要在加载数据之前(before ajax)显示loading效果,在数据返回之后(ajax completed)结束loading效果,就可以了。 但是页面的加载进度,需要一点技巧。 页面加载进度一直以来都是一个常见而又晦涩的需求,常见是因为它在某些“重”网页(特别是网页游戏)的应用特别重要;晦涩是因为web的特性,各种零散资源决定它很难是“真实”的进度,只能是一种“假”的进度,至少在逻辑代码加载完成之前,我们都不能统计到进度,而逻辑代码自身的进度也无法统计。另外,我们不可能监控到所有资源的加载情况。 所以页面的加载进度都是“假”的,它存在的目的是为了提高用户体验,使用户不至于在打开页面之后长时间面对一片空白,导致用户流失。 既然是“假”的,我们就要做到“仿真”才有用。仿真是有意义的,事实上用户并不在乎某一刻你是不是真的加载到了百分之几,他只关心你还要load多久

Javascript (node.js) Specific Random String Builder [duplicate]

北城余情 提交于 2020-01-05 11:05:20
问题 This question already has answers here : Generate random password string with requirements in javascript (15 answers) How to generate a random password using these requirements? [closed] (3 answers) Closed 6 years ago . I'm looking for an efficient way to build a random string that has specific requirements but can vary in length. It must : Contain at least one uppercase character. Contain at least one lowercase character. Contain at least one number. Contain at least one of the special

Find and Replace for whole page

眉间皱痕 提交于 2020-01-05 09:09:40
问题 I'm trying to create a Find and Replace for the whole page. I'm Using findandreplace which is a mini-plugin which is: function findAndReplace(searchText, replacement, searchNode) { if (!searchText || typeof replacement === 'undefined') { alert("Please Enter Some Text Into the Field"); return; } var regex = typeof searchText === 'string' ? new RegExp(searchText, 'g') : searchText, childNodes = (searchNode || document.body).childNodes, cnLength = childNodes.length, excludes = 'html,head,style

c++ async : how to shuffle a vector in multithread context?

五迷三道 提交于 2020-01-05 08:08:39
问题 Running a multithreaded program, I noticed that the program was running faster using 1 thread compared to 4 threads, despite the CPU having 4 cores. After investigating, I found out that the issue appears only when shuffling something. Below the minimal program I created to reproduce the problem: #include <math.h> #include <future> #include <ctime> #include <vector> #include <iostream> #include <algorithm> #define NB_JOBS 5000.0 #define MAX_CORES 8 static bool _no_shuffle(int nb_jobs){ bool b

c++ async : how to shuffle a vector in multithread context?

会有一股神秘感。 提交于 2020-01-05 08:08:21
问题 Running a multithreaded program, I noticed that the program was running faster using 1 thread compared to 4 threads, despite the CPU having 4 cores. After investigating, I found out that the issue appears only when shuffling something. Below the minimal program I created to reproduce the problem: #include <math.h> #include <future> #include <ctime> #include <vector> #include <iostream> #include <algorithm> #define NB_JOBS 5000.0 #define MAX_CORES 8 static bool _no_shuffle(int nb_jobs){ bool b