// streams/RandomGenerators.java// (c)2017 MindView LLC: see Copyright.txt// We make no guarantees that this code is fit for any purpose.// Visit http://OnJava8.com for more book information.import java.util.*;import java.util.stream.*;public class RandomGenerators {public static <T> void show(Stream<T> stream) {stream.limit(4).forEach(System.out::println);System.out.println("++++++++");}public static void main(String[] args) {Random rand = new Random(47);show(rand.ints().boxed());show(rand.longs().boxed());show(rand.doubles().boxed());// Control the lower and upper bounds:show(rand.ints(10, 20).boxed());show(rand.longs(50, 100).boxed());show(rand.doubles(20, 30).boxed());// Control the stream size:show(rand.ints(2).boxed());show(rand.longs(2).boxed());show(rand.doubles(2).boxed());// Control the stream size and bounds:show(rand.ints(3, 3, 9).boxed());show(rand.longs(3, 12, 22).boxed());show(rand.doubles(3, 11.5, 12.3).boxed());}}/* Output:-11720287791717241110-2014573909229403722++++++++29552893544413037713476817843704654257-89171176941345214744941259272818818752++++++++0.26136103442839640.05086735705568990.80371554496039990.7620665811558285++++++++16101112++++++++65995458++++++++29.8677768107857424.8396844780461120.0924711233201424.046793846338723++++++++11699766061947946283++++++++2970202997824602425-2325326920272830366++++++++0.70242545106315270.6648552384607359++++++++677++++++++171220++++++++12.2787241423669111.73208544973619512.196509449817267++++++++*/
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。