Click here to Skip to main content
15,899,676 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            Random pin = new Random();

            for (int i = 1; i <= 1; i++)
            {
                string path = @"D:\try\"+pin+".txt;"
                Console.WriteLine(pin.Next(59372));



                using (StreamWriter writer = new StreamWriter(path))
                {
                    writer.WriteLine(pin);
                }


            }
        }
    }

no output in path...
Posted
Updated 17-Mar-14 20:55pm
v2

Random is a class that provides functions to produce random sequences. See examples in Random Class[^].
It's always advised to look up the class help files.
pin for itself can not be used to do ...string + pin....
You have to get a random number first and store in a variable. Use that variable for your file name and for storing in the file.
Cheers
Andi
 
Share this answer
 
Comments
jone,jake 18-Mar-14 3:06am    
can u send me the right code? newbie here
Andreas Gieriet 18-Mar-14 5:43am    
You won't learn it when I send you the solution.
If you don't get the solution from the help file mentioned above, I can't help you, sorry.
Cheers
Andi
C#
static void Main(string[] args)
        {
            Random pin = new Random();
            string path = @"C:\test.txt";
            using (StreamWriter writer = new StreamWriter(path))
            {
                for (int i = 0; i <= 1; i++)
                {
                    Console.WriteLine(pin.Next(59372));
                    writer.WriteLine(pin.Next(59372));
                }
            }
        }
 
Share this answer
 
v3
Comments
jone,jake 18-Mar-14 3:09am    
no random number output in path sir
[no name] 18-Mar-14 3:52am    
See I hope there was a problem in loop also where i start value was 1 and checking condition with 1 that why it was not executed hope so. Again I have updated the above solution please check it
jone,jake 18-Mar-14 4:12am    
same sir... no output in path... :(
[no name] 18-Mar-14 4:37am    
I have just changed your path, fixed file name, and pin.next(59372) the it's working fine ! See it agian
jone,jake 18-Mar-14 5:30am    
tnx a lot sir..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900