Friday, 17 November 2017

Java Program to Use rand and srand Functions


Code:

import java.util.Random;
import java.util.UUID;

public class Rand_and_Srand 
{
    public static void main(String args[])
    {
        System.out.println("The numbers using rand");
        for(int i=0; i<5 font="" i="">
        {
            Random rand = new Random();
            System.out.println(Math.abs(rand.nextInt()));
        }

        System.out.println("The numbers using srand");
        for(int i=0; i<5 font="" i="">
        {
            System.out.println(Math.abs(UUID.randomUUID().getMostSignificantBits()));
        }
    }
}


Output:

The numbers using rand
1339557437
636169175
1207287888
1539694038
1040189301
The numbers using srand
301709257092546335
8798470719933102847
3480203219570178904
3272351410737399038
2158529096808811162


More Java Programs:














100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...