草庐IT

random-time-generation

全部标签

javascript - 影响 Math.random()

我正在寻找一种方法来影响Math.random()。我有这个函数来生成一个从最小值到最大值的数字:varrand=function(min,max){returnMath.floor(Math.random()*(max-min+1))+min;}有没有办法让它比中间的数字更容易得到低和高的数字?例如;rand(0,10)将返回比其余更多的0,1,9,10。 最佳答案 Isthereawaytomakeitmorelikelytogetalowandhighnumberthananumberinthemiddle?是的。您想要更改生

javascript - 如何在 JavaScript 中使用 Math.random 进行测试?

我有一个函数可以在最小值和最大值之间选择一个随机值。因此,当我进行测试时,我会测试该值是否介于最小值和最大值之间。但是由于我的应用程序出现了一些故障,因此测试有时会通过,有时会由于随机性而失败。覆盖/模拟Math.random()以返回0和1并测试我的值是否与最大值或最小值相同是个好主意吗?或者是否有更好的方法来测试JavaScript中的随机性?这是将用于创建随机数的函数:functionconstrain(min,max){returnMath.round(Math.random()*(max-min)+min)} 最佳答案 S

javascript - Yeoman Angular Generator Grunt Build scripts/vendor.js 为空

我已经通过yoangular[project-name]生成了一个Angular项目,尝试通过gruntbuild构建它。我检查了dist/scripts/vendor.d41d8cd9.js文件,发现它是空的。我找到了this问题,它根本没有帮助我。如果有人能指出我正确的方向,将不胜感激。 最佳答案 我以某种方式找到了答案,我更改了build:js标签:到:它解决了我的问题:) 关于javascript-YeomanAngularGeneratorGruntBuildscripts/v

javascript - 三.js : face4 generates triangle instead of square

我正在尝试使用tree.js自定义几何图形生成一个正方形。但是这段代码varcubeGeo=newTHREE.Geometry();cubeGeo.vertices.push(newTHREE.Vector3(-25,25,-25));cubeGeo.vertices.push(newTHREE.Vector3(25,25,-25));cubeGeo.vertices.push(newTHREE.Vector3(-25,-25,-25));cubeGeo.vertices.push(newTHREE.Vector3(25,-25,-25));cubeGeo.faces.push(new

javascript - 三个 : How could we insert a locally loaded mesh into the canvas being generated by Three to display it?

您好,感谢您阅读这个问题:我正在学习Threejs,目前我有一个奇怪的困难:我已经学会了如何使用加载器以纯HTML/JAVASCRIPT加载格式为NRRD的本地文件:这里是repo:https://github.com/YoneMoreno/LoadNRRDInThreeJSExample作为它的外观示例:但是,我想将前面的示例与React集成。我研究了如何使用这个SO线程关联React和Three:Renderingthree.jselementinReact?现在我的代码是这样的:/*globalTHREE*/importReactfrom'react';classLoadNRRD

javascript - Math.random 随机位数

对于Math.random应该产生多少随机位有什么要求吗?我对Chrome和Firefox的实现做了一些测试,将结果转换为十六进制以检查位,Firefox27.0.1给出的结果如下0x1.de619579d56f3p-10x1.ef1ada9306decp-20x1.df3b75e208ce6p-1而Chrome版本33.0.1750.154m给出0x1.1190f39c00000p-20x1.b959e3b600000p-10x1.90f614b400000p-2相比之下,这真是太可怕了。它似乎是一个32位的结果,而Firefox的值似乎使用53个随机位。

javascript - Angular 和 Observable : how to avoid multiple requests to API within a given time

我在Angular4应用程序中有类似的东西(为了示例,我删除了代码)@Injectable()exportclassSomeService{constructor(privatehttp:Http){}get(id:number){returnthis.http.get('http://somedomain/somemodel/${id}.json');}}一些组件使用它来进行API调用。constructor(privatesomeService:SomeService){}...someMethod(){//codehere...this.someService.get(2).su

javascript - contentEditable + selectAll : Firefox won't allow keyboard input on dynamically generated content

我在使用包含contenteditable="true"属性的动态生成元素的Firefox中遇到问题(其他浏览器似乎工作正常):如果我selectAll(动态地或使用我的鼠标),Firefox将不允许键盘输入。请看我的jsFiddleExample以供引用。这似乎只影响Firefox。$(document).ready(function(){$('.edit').live('dblclick',function(){document.execCommand('selectAll',false,null);});$('#live').append('Thiscontentisgenera

javascript - Yeoman.io 在安装 generator-angular 时出现问题

写问题时使用了谷歌翻译器。在新安装的ubuntu14.04上设置nodejs-sudoadd-apt-repositoryppa:chris-lea/node.jssudoapt-getupdatesudoapt-getinstallpython-software-propertiespythong++makenodejs然后安装哟-sudonpmi-gyo然后我安装generator-angular-sudonpmi-ggenerator-angular从您打开终端的目录并安装generator-angular-yoangular并得到很多错误。为什么?如何解决?SergioLope

execution failed for task ‘:×××:compiledebugkotlin‘解决办法--Android Studio

一个月前创建的一个kotlinactivity项目,当时使用的kotlin版本是1.5×,后来在当前项目下创建了一个compose模块,建完后手贱更新了kotlin版本(1.6.10)。运行composeactivity的时候就报这个错误:executionfailedfortask':composetutorial1:compiledebugkotlin'简言之就是kotlin版本和compose版本不兼容的问题,要么改项目的compose版本,要么改kotlin版本。在网上找了很多经验没解决,查官方文件找到了兼容的compose版本预发布Kotlin兼容性如需详细了解与Kotlin预发布版