how to generate random numbers of the same at each time of execution of thm

dear friends

i am facing a problem that the random numbers generated at time of each exectuion of the program are not the same, i want to generate the same random numbers every time time i run the program. i need your help. i am giving the code in c++ if anybody can help in providing the solution so that i get the same random numbers at every run of the program. waiting for your help

wit regards

jaya shankar

#include<iostream.h>

#include<stdio.h>

#include<stdlib.h>

#include<time.h>

#include<math.h>

class density

{

int s[150][150],parent[150][150],i,j,l,n,loop;

public:

void bd(void);

void css(void);

};

void density :: bd(void)

{

cout<<"ENTER THE POPULATION SIZE = ";

cin>>n;

cout<<"\nENTER THE NO.OF LOOPS = ";

cin>>loop;

for(i=0;i<n;i++)

for(j=0;j<80;j++)

{

s[j]=rand()%2;

cout><<"s:"<<s[j];

}

}

void density :: css(void)

{

int a,b;

float c;

for(i=0;i<n;i=i+2)

{

b=rand()%100;

cout><<"random b="<<b;

}

}

main()

{

density d;

d.bd();

d.css();

}

>

[1332 byte] By [jayashankar] at [2007-9-27 1:56:34]
# 1

package mypackage;

public class Density {

private int s[][] = new int[150][150];

private int parent[][] = new int[150][150];

private int i;

private int j;

private int l;

private int n;

private int loop;

public void bd(int n, int loop)

{

System.out.println(" Population size entered:"+ n);

System.out.println(" No. of loops entered:"+ loop);

for(i = 0; i < n; i++)

for(j = 0; j < loop; j++)

{

java.util.Random rand = new java.util.Random();

s[i][j] = rand.nextInt()%2;

System.out.println("s:"+s[i][j]);

}

}

public void css()

{

int a, b;

float c;

for(i=0; i < n; i=i+2)

{

java.util.Random rand = new java.util.Random();

b = rand.nextInt() % 100;

System.out.println("random b="+b);

}

}

public static void main(String args[])

{

Density d = new Density();

// note here that the bd function declaration is changed

// as JAVA doesnot have something in comon to cin

// so i am passing argument to the program itself. or you can

// improvise to put some swing components and ask the user to enter.

d.bd(Integer.parseInt(args[0]),Integer.parseInt(args[1]));

d.css();

}

public Density() {

}

}

rgiri1 at 2007-7-4 20:36:44 > top of Java-index,Other Topics,Java Community Process (JCP) Program...