uuid

真随机数,伪随机数,UUID SecureRandom

空扰寡人 提交于 2019-12-20 10:21:40
1. 什么是真随机数? 真随机数有一个非常基本的特征就是 不可预测性 2.什么是伪随机数 大部分程序和语言中的随机数,确实都只是伪随机。是由可确定的函数(常用线性同余),通过一个种子(常用时钟),产生的。这意味着:如果知道了种子,或者已经产生的随机数,都可能获得接下来随机数序列的信息(可预测性)。 在java中存在一个Random类,我们查看其源码就能发现,其就是使用的算法来实现的随机数,算法产生的随机数都不能算真随机数,有其自身的规则。直观来想,计算机就是一种确定的,可预测的的设备:一行行的代码是固定的,一步步的算法是固定的,一个个与非门是固定的。通过这些固定的东西自身产生真随机,当然不可能。 3. 怎么在计算机上得到真随机数 想直接利用算法得到真随机数,这有点难度,但是也不是没有办法的,计算机不能产生随机数,但是现实世界中是有非常多的随机因素的,将这种随机因素引入计算机,就能实现真随机 Unix 内核中的随机数发生器(/dev/random),理论上它能产生真随机。即这个随机数的生成,独立于生成函数,这时我们说这个随机数发生器是非确定的(不可预见的)。 具体来讲,Unix 维护了一个熵池,不断收集非确定性的设备事件,即机器运行环境中产生的硬件噪音,来作为种子。 比如说,时钟,IO 请求的响应时间,特定硬件中断的时间间隔,键盘敲击速度,鼠标位置变化,甚至周围的电磁波等等…

How to choose between UUIDs, autoincrement/sequence keys and sequence tables for database primary keys?

為{幸葍}努か 提交于 2019-12-20 08:49:02
问题 I'm looking at the pros and cons of these three primary methods of coming up with primary keys for database rows. So assuming I am using a database that supports more than one of these methods, is there a simple heuristic to determine what the best option would be for me? How do considerations such a distributed/multiple masters, performance requirements, ORM use, security and testing have on the choice? Any unexpected drawbacks that one might run into? 回答1: UUIDs Unless these are generated

MongoDB - Advantage of using 12 bytes string as unique identifier instead of incremental value

天涯浪子 提交于 2019-12-20 05:38:30
问题 Is there any specific reason for MongoDB generating uuid as unique identifier instead of incremental values as unique identifier?. 回答1: Incrementing values or sequences require a central point of reference which is a limiting factor for scaling. ObjectIDs are designed to be reasonably unique IDs that can be independently generated in a distributed environment with monotonically increasing values (a leading timestamp component) for approximate ordering. ObjectIDs are typically generated by

Formating UUID String without REGEXP_REPLACE and PL/SQL

可紊 提交于 2019-12-20 03:10:30
问题 I'd like to format the result of the sys_guid() function such as proposed in this answer select regexp_replace(rawtohex(sys_guid()) , '([A-F0-9]{8})([A-F0-9]{4})([A-F0-9]{4})([A-F0-9]{4})([A-F0-9]{12})' , '\1-\2-\3-\4-\5') as FORMATTED_GUID from dual From performance reasons I'd like to avoid the usage of regexp_replace (as I process large number of records). My scenario can be simplified to this use case: select rawtohex(sys_guid()) GUID from dual connect by level <= 2; Obviously I can't use

Neo4j / Strategy to keep history of node changes

 ̄綄美尐妖づ 提交于 2019-12-20 02:24:04
问题 Let's assume a graph dealing with cars. Each Car can evolve over time, and I need to keep track of those changes. (in order to be able to track some inconsistency of evolution etc...) I thought about implementing a copy-on-write mechanism (like LinkedIn seems to do), meaning creating a complete new Car node each time one of the Car 's properties changes. I would end up with a graph like this: (Ferrari)-[:CURRENT]->(V3)-[:PREVIOUS]->(V2)-[:PREVIOUS]->(V1) I'm specifically interested in

Is there a way to create an auto-incrementing Guid Primary Key in an Oracle database?

霸气de小男生 提交于 2019-12-20 01:58:35
问题 I mostly work with sql-server (when I do work with databases) and I am trying to learn pl-sql. Is there any equivalent to sql-server's auto-generated Guid as primary keys in Oracle? 回答1: You can use SYS_GUID() to generate a GUID, and use it as DEFAULT value of a column: CREATE TABLE test_table ( uid_col RAW(32) DEFAULT SYS_GUID(), some_val VARCHAR2(10) ); EDIT : See answers to this question for more details. 回答2: Make char or varchar2 column data type overwise raw to pass future troubles. 来源:

How to mock uuid with Jest

匆匆过客 提交于 2019-12-19 22:22:43
问题 so on my search for an answer to my problem I found this post: Jest: How to globally mock node-uuid (or any other imported module) I already tried the answer but I can't seem to use it properly, as it´s giving me an undefined error. I'm new to the testing scene so please excuse any major errors: This was my first approach const mockF = jest.mock('uuid'); mockF.mockReturnValue('12345789'); But it wouldn't recognize the functions. "mockF.mockReturnValue is not a function" among others I tried.

PHP verify valid UUID

匆匆过客 提交于 2019-12-19 10:22:44
问题 I found the following Javascript function in another answer: function createUUID() { var s = []; var hexDigits = "0123456789abcdef"; for (var i = 0; i < 36; i++) { s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1); } s[14] = "4"; s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); s[8] = s[13] = s[18] = s[23] = "-"; var uuid = s.join(""); return uuid; } This creates an RFC valid UUID/GUID in javascript.. What I want to know is if there is a way to validate the string once it arrives

Is there a UUID type of value in Linux that can uniquely identify an instance of a VM?

匆匆过客 提交于 2019-12-19 09:43:37
问题 I have an app that runs in Linux. Each one will try to get a UUID from OS and report to a centralized server. I want to make sure all instance are running with globally unique UUID. If the linux is on bare metal, it can just read the UUID (say, from dmidecode command). But if it's on VM, the UUID (from dmidecode) can potentially be equal since the VM can be copied or moved. Any ideas? By the way, for Linux running on physical hardware (not on VM), if user changes memory, NIC etc, will UUID

get the unix timestamp from type 1 uuid

冷暖自知 提交于 2019-12-19 09:25:31
问题 In our java application we are trying to get the unix time from the type 1 uuid. But its not giving the correct date time values. long time = uuid.timestamp(); time = time / 10000L; // Dividing by 10^4 as its in 100 nanoseconds precision Calendar c = Calendar.getInstance(); c.setTimeInMillis(time); c.getTime(); Can some one please help ? Edit: Fixed the divisor(10^4) 回答1: From the docs for timestamp() : The resulting timestamp is measured in 100-nanosecond units since midnight, October 15,