random

createToken()

和自甴很熟 提交于 2020-02-26 00:48:03
public static string createToken ( ) { Random ro = new Random ( 10 ) ; long tick = DateTime . Now . Ticks ; Random ran = new Random ( ( int ) ( tick & 0 xffffffffL ) | ( int ) ( tick > > 32 ) ) ; return ran . Next ( ) . ToString ( ) ; } 来源: CSDN 作者: ljm_lijingming 链接: https://blog.csdn.net/ljm_lijingming/article/details/104500851

[Java] 猜数字

余生长醉 提交于 2020-02-26 00:13:35
猜1~100数字,提示大或小; import java . util . Random ; import java . util . Scanner ; public class test { public static void main ( String [ ] args ) { Random r = new Random ( ) ; int number = r . nextInt ( 100 ) + 1 ; // 1~100 gn : while ( true ) { Scanner sc = new Scanner ( System . in ) ; System . out . println ( "请输入你要猜的数字:" ) ; int guessNumber = sc . nextInt ( ) ; if ( guessNumber > number ) { System . out . println ( "你猜的数字" + guessNumber + "大了" ) ; } else if ( guessNumber < number ) { System . out . println ( "你猜的数字" + guessNumber + "小了" ) ; } else { System . out . println ( "恭喜你猜中了" ) ; break

Java中生成随机数Random、ThreadLocalRandom、SecureRandom、Ma

冷暖自知 提交于 2020-02-25 23:45:31
我们来说说Java常见的生成随机数的几种方式:Random,ThreadLocalRandom,SecureRandom;其实产生随机数有很多种方式但我们常见的就这几种,如果需要详细了解这个三个类,可以查看JAVA API. Random random = new Random(); int a = random.nextInt(5);//随机生成0~4中间的数字 其实Random是有构造函数的,他的参数可以传一个long类型的值,当使用空的构造的时候,使用的实际上是System.nanoTime()也就是当前时间毫秒数的值,我们把这个叫做 种子 。 种子是干什么的呢,实际上我们生成的随机数都是伪随机数,而想要使我们生成的随机数强度更高,就需要更好的 算法 和种子。一般情况下,要使用Random去生成随机数,直接用空构造函数就可以了。那么这个种子到底有什么用呢,实际上读者去试验一下就知道了,我们使用固定随机数,比如1,然后我们连续次去new这个Random,然后去生成一个随机数,像下面这样,你会发现,三个数的结果是一样的。 /** * -1157793070 * 1913984760 * 1107254586 */ @Test public void test2(){ Random random = new Random(10); for (int i = 0; i < 3; i+

Java ——变量类型

邮差的信 提交于 2020-02-25 23:43:17
变量声明 int a, b, c; // 声明三个int型整数:a、 b、c int d = 3, e = 4, f = 5; // 声明三个整数并赋予初值 byte z = 22; // 声明并初始化 z String s = "runoob"; // 声明并初始化字符串 s double pi = 3.14159; // 声明了双精度浮点型变量 pi char x = 'x'; // 声明变量 x 的值是字符 'x'。 Java语言支持的变量类型有: 类变量 :独立于方法之外的变量,用 static 修饰。 实例变量 :独立于方法之外的变量,不过没有 static 修饰。 局部变量 :类的方法中的变量。 public class Variable{ static int allClicks=0; // 类变量 String str="hello world"; // 实例变量 public void method(){ int i =0; // 局部变量 } } 举例: package hello; //首先要知道变量应该是赋值以后才能使用的,但是有些不必人为赋值就有默认初始值,但是有些要人为定义初始值 //所以有些直接使用的并不是没有赋值,而是系统自定义了初始值,所以不会报错 public class Variable { public String instance =

07Scanner类、Random类、ArrayList类

邮差的信 提交于 2020-02-25 22:17:15
day07Scanner类、Random类、ArrayList类 第一章 API 概述 API(Application Programming Interface),应用程序编程接口。 Java API是一本程序员的 字典 ,是JDK中提供给 我们使用的类的说明文档。这些类将底层的代码实现封装了起来,我们不需要关心这些类是如何实现的,只需要学 习这些类如何使用即可。所以我们可以通过查询API的方式,来学习Java提供的类,并得知如何使用它们。 API的使用步骤 打开帮助文档。 点击显示,找到索引,看到输入框。 你要找谁?在输入框里输入,然后回车。 看包。java.lang下的类不需要导包,其他需要。 看类的解释和说明。 学习构造方法。 使用成员方法。 第2章Scanner类 lang包不需要导包 2.1 Scanner功能 Scanner类的功能:可以实现键盘导入数据,到程序中. 2.2 引用类型使用步骤 1.导包 格式:import 包路径.类名称; 如果需要使用的目标类,和当前类位于同一包下,则可以省略导报语句不写. 只有Java.lang包下的内容不需要导包,其他的包都需要import语句; 举例: Java.util.Scanner; 2.创建对象 格式:类名称 = new 类名称(); 举例 Scanner sc = new Scanner(System.in); 3

Is there a reverse way to find number of people with given 0.5 probability that two people will have same birthday but no using mathematical formula?

孤人 提交于 2020-02-25 06:16:06
问题 I'm doing birthday paradox, and want to know how many people can meet 0.5 probability that two people have same birthday by using python. I have tried no using mathematical formula to find probability with given the number of people by using random and randint in python import random def random_birthdays(): bdays = [] bdays = [random.randint(1, 365) for i in range(23)] bdays.sort() for x in range(len(bdays)): while x < len(bdays)-1: print x if bdays[x] == bdays[x+1]: #print(bdays[x]) return

How to generate a RNGCryptoServiceProvider-like number in TSQL

那年仲夏 提交于 2020-02-25 05:50:54
问题 Does anyone know of a way to generate a RNGCryptoServiceProvider-like random number in T-SQL without having to register any .NET Assemblies? 回答1: SELECT CHECKSUM(NEWID()) gives you a 32 signed integer based on GUIDs. You can use this as base: it's pretty much the best SQL way You can use it to seed RAND (because RAND is the same for all rows in a single select. SELECT RAND(CHECKSUM(NEWID())) A signed 64 bit integer: SELECT CAST(CHECKSUM(NEWID()) as bigint) * CAST(CHECKSUM(NEWID()) as bigint)

How to generate a RNGCryptoServiceProvider-like number in TSQL

▼魔方 西西 提交于 2020-02-25 05:50:19
问题 Does anyone know of a way to generate a RNGCryptoServiceProvider-like random number in T-SQL without having to register any .NET Assemblies? 回答1: SELECT CHECKSUM(NEWID()) gives you a 32 signed integer based on GUIDs. You can use this as base: it's pretty much the best SQL way You can use it to seed RAND (because RAND is the same for all rows in a single select. SELECT RAND(CHECKSUM(NEWID())) A signed 64 bit integer: SELECT CAST(CHECKSUM(NEWID()) as bigint) * CAST(CHECKSUM(NEWID()) as bigint)

常见的中文(Unicode编码)

为君一笑 提交于 2020-02-24 20:35:36
String base = "\u7684\u4e00\u4e86\u662f\u6211\u4e0d\u5728\u4eba\u4eec\u6709\u6765\u4ed6\u8fd9\u4e0a\u7740\u4e2a \u5730\u5230\u5927\u91cc\u8bf4\u5c31\u53bb\u5b50\u5f97\u4e5f\u548c\u90a3\u8981\u4e0b\u770b\u5929\u65f6\u8fc7 \u51fa\u5c0f\u4e48\u8d77\u4f60\u90fd\u628a\u597d\u8fd8\u591a\u6ca1\u4e3a\u53c8\u53ef\u5bb6\u5b66\u53ea\u4ee5 \u4e3b\u4f1a\u6837\u5e74\u60f3\u751f\u540c\u8001\u4e2d\u5341\u4ece\u81ea\u9762\u524d\u5934\u9053\u5b83\u540e \u7136\u8d70\u5f88\u50cf\u89c1\u4e24\u7528\u5979\u56fd\u52a8\u8fdb\u6210\u56de\u4ec0\u8fb9\u4f5c\u5bf9\u5f00 \u800c\u5df1\u4e9b\u73b0\u5c71\u6c11\u5019\u7ecf

机器学习-Random Sample Consensus Regression(RANSAC)回归

那年仲夏 提交于 2020-02-24 05:19:09
Section I: Brief Introduction on RANSAC Linear regression models can be heavily impacted by the presence of outliers . In certain situations, a very small subset of our data can have a big effect on the estimated model coefficients. There are mant statistical tests that can be used to detect outliers. However, removing outliers always requiresour own judgement as data scientists as well as domain knowledge. As an alternative to throwing out outliers, a robust method of regression using the random sample consensus (RANSAC) algorithm, which fits a regression model to a subset of the data, the so