`

Random usage

 
阅读更多

public class RandomTest

{

      public static void main(String[] args)

      {

            Random rand1 = new Random(47);

            Random rand2 = new Random(47);

            for (int i = 0; i < 100; i++)

            {

                  System.out.print(rand1.nextInt(100) + "   ");

                  System.out.println(rand2.nextInt(100) + " ");

            }

      }

}

 

After running this program, if you will see that,

1)    rand1 and rand2 will always generate the same number.

2)    No matter how many times you run, the number serial never changes. It’s always the same.

 

The reason for this is because of the ---- “seed”.

 

      Random rand1 = new Random(47);

 

Here, 47 is the seed. 47 will make it fixed, what number it is in some order.

 

If you want to get really random number, you need to use the default non-argument constructor for Random class.

 

分享到:
评论

相关推荐

    chinese-random-skill:使用 Node.js 生成中文技能

    Usage Generate a Full Name Automatically Using generate function: var randomSkill = require("chinese-random-skill"); console.log(randomName.generate()); Some Skill Names it Generated 砚赏请汉宝典 祚...

    pick-random-cli:从列表中选择随机项目

    Usage $ pick-random &lt;item&gt; … [--count=] $ cat newline-separated-picks.txt | pick-random Examples $ pick-random unicorn rainbow cake pony --count=2 pony rainbow $ pick-random yes no $ pick-...

    randomforest-density-python:Python中密度估计的随机森林

    randomforest-density: density estimation using random forests. optional arguments: -h, --help show this help message and exit -l LEAF, --leaf LEAF Choose what leaf estimator to use (Gaussian [ ' ...

    NIST SP800-22rev1a.pdf

    However, no set of statistical tests can absolutely certify a generator as appropriate for usage in a particular application, i.e., statistical testing cannot serve as a substitute for cryptanalysis....

    S50 7字节UID 改为随机UID

    14443-3 and optional usage of a selection process shortcut 3. UIDF2: anti-collision and selection with a single size random ID according to ISO/IEC 14443-3 4. UIDF3: anti-collision and selection with ...

    Android代码-simple-annotation-processor

    Simple Annotation Processor ...Simple usage of them: public class TestActivity extends AppCompatActivity { @RandomInt String randomInteger; @RandomInt(minValue = 1, maxValue = 100) int random

    paper:CLI工具,可从Unsplash.com设置随机墙纸

    Usage: ./paper [options] Paper - A Random Wallpaper Application A CLI Tool to set a random wallpaper from Unsplash.com Options: -d, --download Only download the wallpaper -D, --dir &lt;directory&gt; ...

    PSPNet_PyTorch:PSPNet的实现

    usage: train.py [-h] [--is-training] [--learning-rate LEARNING_RATE] [--weight-decay WEIGHT_DECAY] [--momentum MOMENTUM] [--power POWER] [--dataset DATASET] [--random-mirror] [--random-scale] [--...

    tg-bot:电报机器人

    #Telegram Bot Telegram...help() : Display this usage informationdice() : Returns a random number 1-6quote() : Returns a random fortune cookie quoteping() : Pong backweather() : Returns the weather status

    Machine-Learning-in-Python-Essential-Techniques-for-Predictive-Analysis

    This book covers two broad classes of machine learning algorithms: penalized linear regression (for example, Ridge and Lasso) and ensemble methods (for example, Random Forests and Gradient Boosting)....

    使用拥挤距离的多目标粒子群优化算法(C)

    Commercial usage of these codes is prohibited * * without prior knowledge of the authors. In no way will the authors * * be held responsible for any possible faulty operation of * * software/...

    IP-Address-Generator:为24个子网生成动态ip的程序

    IP地址生成器为 24 个子网生成随机 ip 的程序,输出是文本,用于脚本的预期用途,其中文本输出可以直接使用##如何构建$&gt;mkdir build $&gt;cd build $&gt;gnatmake ../generate_random_ip.adb 尚无安装机制##Usage ###Help ...

    表情搜索工具Emojisearcher.zip

    安装$ npm install -g emoji-cli使用(查看帮助文档)Usage: emoji  Options:  -h, --help output usage information  -V, --version output the version number  -r, --random pick a ...

    YAG-PDB.xyz-Custom-Commands

    爱神的自定义命令 介绍 你好! 欢迎来到我的Git-Hub Repo,在这里我可以上传一些我的... usage : -random nickname 嵌入文字 ::将文本转换为嵌入// ViceVersa! usage : -embed &lt;@#CHANNEL&gt; &lt;MESSAGE-ID:Whole

    阿里强化学习研究平台GymStarCraft.zip

    Usage使用 Chaoslauncher BWAPI 启动 StarCraft 服务器。运行:cd examples python random_agent.py --ip $server_ip --port $server_port$server_ip 和 $server_port 是运行 StarCraft 的服务器的 ip 和...

    python_mpd_toys:玩MPD和python-mpd2

    Usage: random_album.py [options]Options: -h, --help show this help message and exit -a ARTIST, --artist=ARTIST Specifies an artist to limit album choices from; needs to be a quoted string -y YEAR, --...

    identywaf.zip

    Usage: python identYwaf.py [options] |url&gt; Options: --version Show program's version number and exit -h, --help Show this help message and exit --delay=DELAY Delay (sec) between tests (default: 0)...

    SQL_Assistant_9.5.469_Enterprise_Edition 破解

    SA0033354 - Import from Excel: integer values can change to random numbers. SA0033310 - Cloned connections don't always work correctly. SA0033327 - $$...$$ macro usage with SQL Server environments, ...

    随机点名-图形界面-excel处理(Python)

    8. **文档编写**:`食用说明_usage.docx`文件可能是项目使用指南,包含了如何运行和使用这个随机点名程序的详细步骤,对于用户来说是重要的参考文档。 综合以上,这个项目展示了Python作为全功能编程语言的能力,...

    freshpaper:此实用程序会自动将来自各种来源的当天墙纸设置为您的桌面墙纸

    新鲜纸 Freshpaper会自动将当天照片或或或为桌面墙纸。 适用于Windows,macOS和Linux。 ...Usage: freshpaper [OPTIONS] COMMAND [ARGS]... Options: --source [bing|nasa|unsplash_random|nat_g

Global site tag (gtag.js) - Google Analytics