首页 > 代码库 > 七种语言生成随即数

七种语言生成随即数

   Java

import java.util.Random;import java.util.Arrays;public class RandJava{	public static void main(String args[]){		int []seeds = {10,23,7,19,1,22,7};		System.out.println(Arrays.toString(seeds));		for(int i=0; i<6; i++){			Random r = new Random(seeds[i]);			System.out.println(r.nextInt(33)+1);		}		Random r = new Random(seeds[6]);		System.out.println(r.nextInt(16)+1);	}}

结果

Ruby

seeds = [10,23,7,19,1,22,7]print seedsputsfor i in seeds[0..5]	srand(i)	puts rand(33)+1endsrand(seeds[6])puts rand(16)+1

结果

七种语言生成随即数