How to randomly generate a word in a CSV file [duplicate]2019 Community Moderator ElectionHow do I generate a random int number?Writing data into CSV file in C#How do I enumerate an enum in C#?How to create Excel (.XLS and .XLSX) file in C# without installing Ms Office?How to concatenate text from multiple rows into a single text string in SQL server?How to output MySQL query results in CSV format?Dealing with commas in a CSV fileSave PL/pgSQL output from PostgreSQL to a CSV fileHow do I remedy the “The breakpoint will not currently be hit. No symbols have been loaded for this document.” warning?How do I generate a random int number?How to import CSV file data into a PostgreSQL table?Pandas writing dataframe to CSV file

Will the concrete slab in a partially heated shed conduct a lot of heat to the unconditioned area?

Why restrict private health insurance?

Sort array by month and year

How to distinguish easily different soldier of ww2?

Averaging over columns while ignoring zero entries

Why do we say 'Pairwise Disjoint', rather than 'Disjoint'?

Should we avoid writing fiction about historical events without extensive research?

Exempt portion of equation line from aligning?

A running toilet that stops itself

Rationale to prefer local variables over instance variables?

Is there a math expression equivalent to the conditional ternary operator?

Too soon for a plot twist?

Why does this boat have a landing pad? (SpaceX's GO Searcher) Any plans for propulsive capsule landings?

Has a sovereign Communist government ever run, and conceded loss, on a fair election?

Is it appropriate to ask a former professor to order a library book for me through ILL?

Unfamiliar notation in Diabelli's "Duet in D" for piano

3.5% Interest Student Loan or use all of my savings on Tuition?

Is this Paypal Github SDK reference really a dangerous site?

How does learning spells work when leveling a multiclass character?

PTIJ: Sport in the Torah

A vote on the Brexit backstop

Issue with units for a rocket nozzle throat area problem

An Undercover Army

What does *dead* mean in *What do you mean, dead?*?



How to randomly generate a word in a CSV file [duplicate]



2019 Community Moderator ElectionHow do I generate a random int number?Writing data into CSV file in C#How do I enumerate an enum in C#?How to create Excel (.XLS and .XLSX) file in C# without installing Ms Office?How to concatenate text from multiple rows into a single text string in SQL server?How to output MySQL query results in CSV format?Dealing with commas in a CSV fileSave PL/pgSQL output from PostgreSQL to a CSV fileHow do I remedy the “The breakpoint will not currently be hit. No symbols have been loaded for this document.” warning?How do I generate a random int number?How to import CSV file data into a PostgreSQL table?Pandas writing dataframe to CSV file










-1
















This question already has an answer here:



  • How do I generate a random int number?

    28 answers



I have a csv file in my file explorer windows 10. This file contains a list of rows e.g.:



John, 5656, Phil, Simon,,Jude, Helen, Andy
Conor, 5656, Phil, Simon,,Jude, Helen, Andy


I am an automated tester using C#, selenium and visual studio. In the application I am testing, there is an upload button which imports the csv file.



How do I randomly change the second number automatically so the update would be 1234 on the first row, 4444 on the second row(just append randomly). I think I would need a random generator for this.



Any advice or snippets of code would be appreciated.










share|improve this question









New contributor




Hyper is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











marked as duplicate by Geert Bellekens, JeffC, DebanjanB selenium-webdriver
Users with the  selenium-webdriver badge can single-handedly close selenium-webdriver questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
2 days ago


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















  • Is the number always made of 4 letters?

    – meJustAndrew
    2 days ago











  • No its unlimited but I would say around the 10 mark would do, numbers by the way not letters

    – Hyper
    2 days ago
















-1
















This question already has an answer here:



  • How do I generate a random int number?

    28 answers



I have a csv file in my file explorer windows 10. This file contains a list of rows e.g.:



John, 5656, Phil, Simon,,Jude, Helen, Andy
Conor, 5656, Phil, Simon,,Jude, Helen, Andy


I am an automated tester using C#, selenium and visual studio. In the application I am testing, there is an upload button which imports the csv file.



How do I randomly change the second number automatically so the update would be 1234 on the first row, 4444 on the second row(just append randomly). I think I would need a random generator for this.



Any advice or snippets of code would be appreciated.










share|improve this question









New contributor




Hyper is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











marked as duplicate by Geert Bellekens, JeffC, DebanjanB selenium-webdriver
Users with the  selenium-webdriver badge can single-handedly close selenium-webdriver questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
2 days ago


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















  • Is the number always made of 4 letters?

    – meJustAndrew
    2 days ago











  • No its unlimited but I would say around the 10 mark would do, numbers by the way not letters

    – Hyper
    2 days ago














-1












-1








-1









This question already has an answer here:



  • How do I generate a random int number?

    28 answers



I have a csv file in my file explorer windows 10. This file contains a list of rows e.g.:



John, 5656, Phil, Simon,,Jude, Helen, Andy
Conor, 5656, Phil, Simon,,Jude, Helen, Andy


I am an automated tester using C#, selenium and visual studio. In the application I am testing, there is an upload button which imports the csv file.



How do I randomly change the second number automatically so the update would be 1234 on the first row, 4444 on the second row(just append randomly). I think I would need a random generator for this.



Any advice or snippets of code would be appreciated.










share|improve this question









New contributor




Hyper is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













This question already has an answer here:



  • How do I generate a random int number?

    28 answers



I have a csv file in my file explorer windows 10. This file contains a list of rows e.g.:



John, 5656, Phil, Simon,,Jude, Helen, Andy
Conor, 5656, Phil, Simon,,Jude, Helen, Andy


I am an automated tester using C#, selenium and visual studio. In the application I am testing, there is an upload button which imports the csv file.



How do I randomly change the second number automatically so the update would be 1234 on the first row, 4444 on the second row(just append randomly). I think I would need a random generator for this.



Any advice or snippets of code would be appreciated.





This question already has an answer here:



  • How do I generate a random int number?

    28 answers







c# visual-studio csv selenium-webdriver






share|improve this question









New contributor




Hyper is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Hyper is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 days ago









Uwe Keim

27.6k32132213




27.6k32132213






New contributor




Hyper is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









HyperHyper

43




43




New contributor




Hyper is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Hyper is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Hyper is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




marked as duplicate by Geert Bellekens, JeffC, DebanjanB selenium-webdriver
Users with the  selenium-webdriver badge can single-handedly close selenium-webdriver questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
2 days ago


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Geert Bellekens, JeffC, DebanjanB selenium-webdriver
Users with the  selenium-webdriver badge can single-handedly close selenium-webdriver questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
2 days ago


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • Is the number always made of 4 letters?

    – meJustAndrew
    2 days ago











  • No its unlimited but I would say around the 10 mark would do, numbers by the way not letters

    – Hyper
    2 days ago


















  • Is the number always made of 4 letters?

    – meJustAndrew
    2 days ago











  • No its unlimited but I would say around the 10 mark would do, numbers by the way not letters

    – Hyper
    2 days ago

















Is the number always made of 4 letters?

– meJustAndrew
2 days ago





Is the number always made of 4 letters?

– meJustAndrew
2 days ago













No its unlimited but I would say around the 10 mark would do, numbers by the way not letters

– Hyper
2 days ago






No its unlimited but I would say around the 10 mark would do, numbers by the way not letters

– Hyper
2 days ago













3 Answers
3






active

oldest

votes


















0














Do you want to append the CSV file before its uploaded to the program or after? Either way it would look something like this:



public File updateFile(string filePath)
List<string> modifiedNames;
using (StreamReader sr = File.OpenText(path))

string s;
while ((s = sr.ReadLine()) != null)

s = s + randomlyGeneratedSuffix();
newEntries.add(s)




using (StreamWriter sw = new StreamWriter("names.txt"))

foreach (string s in modifiedNames)
sw.WriteLine(s);



// return new file?






share|improve this answer








New contributor




Jake Geers is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Before its uploaded

    – Hyper
    2 days ago


















0














Reading the file before uploading, changing the numbers on the second position in csv and writing it again to disk should work. Here is a very simple approach, to help you get started:



 var fileLines = File.ReadAllLines("file.csv");
var randomGenerator = new Random();
var newFileLines = new List<string>();
foreach (var fileLine in fileLines)

var lineValues = fileLine.Split(',');
lineValues[1] = randomGenerator.Next(1000, int.MaxValue).ToString();
var newLine = string.Join(",", lineValues);
newFileLines.Add(newLine);


File.WriteAllLines("file.csv", newFileLines);





share|improve this answer























  • Great it works but how do you read/write file file.csv in a different location?

    – Hyper
    2 days ago











  • Got it just needed to change the / to . Thanks a lot it works perfectly

    – Hyper
    2 days ago











  • @Hyper good job!

    – meJustAndrew
    yesterday


















-1














Instead of updating an existing CSV file for testing I would generate a new one from code.



There are a lot of code examples online how to create a CSV file in C#, for example: Writing data into CSV file in C#



For random numbers you can use the random class: https://docs.microsoft.com/en-us/dotnet/api/system.random?view=netframework-4.7.2






share|improve this answer























  • But the upload button looks in the file explorer

    – Hyper
    2 days ago











  • You generate the file, save it somewhere Selenium can access it, upload it with the button. Maybe you need a shared drive between the test-runner and the Selenium agent. Or upload it somewhere on a webserver so Selenium can download it.

    – Niels van Reijmersdal
    2 days ago


















3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Do you want to append the CSV file before its uploaded to the program or after? Either way it would look something like this:



public File updateFile(string filePath)
List<string> modifiedNames;
using (StreamReader sr = File.OpenText(path))

string s;
while ((s = sr.ReadLine()) != null)

s = s + randomlyGeneratedSuffix();
newEntries.add(s)




using (StreamWriter sw = new StreamWriter("names.txt"))

foreach (string s in modifiedNames)
sw.WriteLine(s);



// return new file?






share|improve this answer








New contributor




Jake Geers is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Before its uploaded

    – Hyper
    2 days ago















0














Do you want to append the CSV file before its uploaded to the program or after? Either way it would look something like this:



public File updateFile(string filePath)
List<string> modifiedNames;
using (StreamReader sr = File.OpenText(path))

string s;
while ((s = sr.ReadLine()) != null)

s = s + randomlyGeneratedSuffix();
newEntries.add(s)




using (StreamWriter sw = new StreamWriter("names.txt"))

foreach (string s in modifiedNames)
sw.WriteLine(s);



// return new file?






share|improve this answer








New contributor




Jake Geers is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Before its uploaded

    – Hyper
    2 days ago













0












0








0







Do you want to append the CSV file before its uploaded to the program or after? Either way it would look something like this:



public File updateFile(string filePath)
List<string> modifiedNames;
using (StreamReader sr = File.OpenText(path))

string s;
while ((s = sr.ReadLine()) != null)

s = s + randomlyGeneratedSuffix();
newEntries.add(s)




using (StreamWriter sw = new StreamWriter("names.txt"))

foreach (string s in modifiedNames)
sw.WriteLine(s);



// return new file?






share|improve this answer








New contributor




Jake Geers is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.










Do you want to append the CSV file before its uploaded to the program or after? Either way it would look something like this:



public File updateFile(string filePath)
List<string> modifiedNames;
using (StreamReader sr = File.OpenText(path))

string s;
while ((s = sr.ReadLine()) != null)

s = s + randomlyGeneratedSuffix();
newEntries.add(s)




using (StreamWriter sw = new StreamWriter("names.txt"))

foreach (string s in modifiedNames)
sw.WriteLine(s);



// return new file?







share|improve this answer








New contributor




Jake Geers is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this answer



share|improve this answer






New contributor




Jake Geers is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









answered 2 days ago









Jake GeersJake Geers

111




111




New contributor




Jake Geers is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Jake Geers is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Jake Geers is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • Before its uploaded

    – Hyper
    2 days ago

















  • Before its uploaded

    – Hyper
    2 days ago
















Before its uploaded

– Hyper
2 days ago





Before its uploaded

– Hyper
2 days ago













0














Reading the file before uploading, changing the numbers on the second position in csv and writing it again to disk should work. Here is a very simple approach, to help you get started:



 var fileLines = File.ReadAllLines("file.csv");
var randomGenerator = new Random();
var newFileLines = new List<string>();
foreach (var fileLine in fileLines)

var lineValues = fileLine.Split(',');
lineValues[1] = randomGenerator.Next(1000, int.MaxValue).ToString();
var newLine = string.Join(",", lineValues);
newFileLines.Add(newLine);


File.WriteAllLines("file.csv", newFileLines);





share|improve this answer























  • Great it works but how do you read/write file file.csv in a different location?

    – Hyper
    2 days ago











  • Got it just needed to change the / to . Thanks a lot it works perfectly

    – Hyper
    2 days ago











  • @Hyper good job!

    – meJustAndrew
    yesterday















0














Reading the file before uploading, changing the numbers on the second position in csv and writing it again to disk should work. Here is a very simple approach, to help you get started:



 var fileLines = File.ReadAllLines("file.csv");
var randomGenerator = new Random();
var newFileLines = new List<string>();
foreach (var fileLine in fileLines)

var lineValues = fileLine.Split(',');
lineValues[1] = randomGenerator.Next(1000, int.MaxValue).ToString();
var newLine = string.Join(",", lineValues);
newFileLines.Add(newLine);


File.WriteAllLines("file.csv", newFileLines);





share|improve this answer























  • Great it works but how do you read/write file file.csv in a different location?

    – Hyper
    2 days ago











  • Got it just needed to change the / to . Thanks a lot it works perfectly

    – Hyper
    2 days ago











  • @Hyper good job!

    – meJustAndrew
    yesterday













0












0








0







Reading the file before uploading, changing the numbers on the second position in csv and writing it again to disk should work. Here is a very simple approach, to help you get started:



 var fileLines = File.ReadAllLines("file.csv");
var randomGenerator = new Random();
var newFileLines = new List<string>();
foreach (var fileLine in fileLines)

var lineValues = fileLine.Split(',');
lineValues[1] = randomGenerator.Next(1000, int.MaxValue).ToString();
var newLine = string.Join(",", lineValues);
newFileLines.Add(newLine);


File.WriteAllLines("file.csv", newFileLines);





share|improve this answer













Reading the file before uploading, changing the numbers on the second position in csv and writing it again to disk should work. Here is a very simple approach, to help you get started:



 var fileLines = File.ReadAllLines("file.csv");
var randomGenerator = new Random();
var newFileLines = new List<string>();
foreach (var fileLine in fileLines)

var lineValues = fileLine.Split(',');
lineValues[1] = randomGenerator.Next(1000, int.MaxValue).ToString();
var newLine = string.Join(",", lineValues);
newFileLines.Add(newLine);


File.WriteAllLines("file.csv", newFileLines);






share|improve this answer












share|improve this answer



share|improve this answer










answered 2 days ago









meJustAndrewmeJustAndrew

2,85732349




2,85732349












  • Great it works but how do you read/write file file.csv in a different location?

    – Hyper
    2 days ago











  • Got it just needed to change the / to . Thanks a lot it works perfectly

    – Hyper
    2 days ago











  • @Hyper good job!

    – meJustAndrew
    yesterday

















  • Great it works but how do you read/write file file.csv in a different location?

    – Hyper
    2 days ago











  • Got it just needed to change the / to . Thanks a lot it works perfectly

    – Hyper
    2 days ago











  • @Hyper good job!

    – meJustAndrew
    yesterday
















Great it works but how do you read/write file file.csv in a different location?

– Hyper
2 days ago





Great it works but how do you read/write file file.csv in a different location?

– Hyper
2 days ago













Got it just needed to change the / to . Thanks a lot it works perfectly

– Hyper
2 days ago





Got it just needed to change the / to . Thanks a lot it works perfectly

– Hyper
2 days ago













@Hyper good job!

– meJustAndrew
yesterday





@Hyper good job!

– meJustAndrew
yesterday











-1














Instead of updating an existing CSV file for testing I would generate a new one from code.



There are a lot of code examples online how to create a CSV file in C#, for example: Writing data into CSV file in C#



For random numbers you can use the random class: https://docs.microsoft.com/en-us/dotnet/api/system.random?view=netframework-4.7.2






share|improve this answer























  • But the upload button looks in the file explorer

    – Hyper
    2 days ago











  • You generate the file, save it somewhere Selenium can access it, upload it with the button. Maybe you need a shared drive between the test-runner and the Selenium agent. Or upload it somewhere on a webserver so Selenium can download it.

    – Niels van Reijmersdal
    2 days ago
















-1














Instead of updating an existing CSV file for testing I would generate a new one from code.



There are a lot of code examples online how to create a CSV file in C#, for example: Writing data into CSV file in C#



For random numbers you can use the random class: https://docs.microsoft.com/en-us/dotnet/api/system.random?view=netframework-4.7.2






share|improve this answer























  • But the upload button looks in the file explorer

    – Hyper
    2 days ago











  • You generate the file, save it somewhere Selenium can access it, upload it with the button. Maybe you need a shared drive between the test-runner and the Selenium agent. Or upload it somewhere on a webserver so Selenium can download it.

    – Niels van Reijmersdal
    2 days ago














-1












-1








-1







Instead of updating an existing CSV file for testing I would generate a new one from code.



There are a lot of code examples online how to create a CSV file in C#, for example: Writing data into CSV file in C#



For random numbers you can use the random class: https://docs.microsoft.com/en-us/dotnet/api/system.random?view=netframework-4.7.2






share|improve this answer













Instead of updating an existing CSV file for testing I would generate a new one from code.



There are a lot of code examples online how to create a CSV file in C#, for example: Writing data into CSV file in C#



For random numbers you can use the random class: https://docs.microsoft.com/en-us/dotnet/api/system.random?view=netframework-4.7.2







share|improve this answer












share|improve this answer



share|improve this answer










answered 2 days ago









Niels van ReijmersdalNiels van Reijmersdal

1,2451128




1,2451128












  • But the upload button looks in the file explorer

    – Hyper
    2 days ago











  • You generate the file, save it somewhere Selenium can access it, upload it with the button. Maybe you need a shared drive between the test-runner and the Selenium agent. Or upload it somewhere on a webserver so Selenium can download it.

    – Niels van Reijmersdal
    2 days ago


















  • But the upload button looks in the file explorer

    – Hyper
    2 days ago











  • You generate the file, save it somewhere Selenium can access it, upload it with the button. Maybe you need a shared drive between the test-runner and the Selenium agent. Or upload it somewhere on a webserver so Selenium can download it.

    – Niels van Reijmersdal
    2 days ago

















But the upload button looks in the file explorer

– Hyper
2 days ago





But the upload button looks in the file explorer

– Hyper
2 days ago













You generate the file, save it somewhere Selenium can access it, upload it with the button. Maybe you need a shared drive between the test-runner and the Selenium agent. Or upload it somewhere on a webserver so Selenium can download it.

– Niels van Reijmersdal
2 days ago






You generate the file, save it somewhere Selenium can access it, upload it with the button. Maybe you need a shared drive between the test-runner and the Selenium agent. Or upload it somewhere on a webserver so Selenium can download it.

– Niels van Reijmersdal
2 days ago




Popular posts from this blog

1928 у кіно

Захаров Федір Захарович

Ель Греко