Total members 11797 |It is currently Sun Sep 22, 2019 1:01 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka






* Project Name:   write Random data To File using java
* Programmer:   msi_333
* Type:   I/O
* Technology:  Java
* IDE:   NetBeans
* Description:   Write Random numbers to File :gOOd:
java code
package rand;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Random;


public class generate {



private Random random=new Random();


public String Generate(int base,int limit) throws IOException
{



int Z=0;


while(true)
{
Z=random.nextInt(limit);
if(Z>=base&&Z<=limit)
{
System.out.println(Z);
return Integer.toString(Z);
}
}



}
public static void main(String[] args)
{
try {
String filename="rand.txt";
BufferedWriter myBuff=new BufferedWriter(new FileWriter(filename,false));

generate mygen=new generate();
myBuff.write(mygen.Generate(7,10));//1
myBuff.newLine();
myBuff.write(mygen.Generate(12,50));//2
myBuff.newLine();
myBuff.write(mygen.Generate(100,102));//3
myBuff.newLine();
myBuff.write(mygen.Generate(1,5));//4
myBuff.newLine();
myBuff.write(mygen.Generate(7,10));//5
myBuff.newLine();
myBuff.write(mygen.Generate(7,10));//6
myBuff.newLine();
myBuff.write(mygen.Generate(7,10));//7
myBuff.newLine();
myBuff.write(mygen.Generate(7,10));//8
myBuff.newLine();
myBuff.write(mygen.Generate(7,10));//9
myBuff.newLine();
myBuff.write(mygen.Generate(7,10));//10
myBuff.newLine();
myBuff.write(mygen.Generate(7,10));//11
myBuff.newLine();
myBuff.write(mygen.Generate(7,10));//12
myBuff.newLine();
myBuff.write(mygen.Generate(7,10));//13
myBuff.newLine();
myBuff.write(mygen.Generate(7,10));//14
myBuff.newLine();


myBuff.flush();
myBuff.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}

}





Attachments:
File comment: Project source code
Rand.rar [9.92 KiB]
Downloaded 617 times
Author:
Mastermind
User avatar Posts: 2707
Have thanks: 74 time

updated.



Author:
Mastermind
User avatar Posts: 2707
Have thanks: 74 time
Post new topic Reply to topic  [ 2 posts ] 

  Related Posts  to : Random To File
 Random to File     -  
 php Random image     -  
 php Random quote     -  
 random forest algorithm classifier     -  
 Pick one or more random entries out of an array     -  
 Generating Random Number in java     -  
 Encrypt/Decrypt a file from source file to target file.     -  
 Applet Game To Shot a Random Ball     -  
 Weka java code for Random Forest Cross Validation     -  
 Cost Sensitive Classifier Random Forest Java in weka     -  



Topic Tags

Java Files and I/O
cron






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com