Pick a random string from csv

Hello,
I’ve found CSV reader for my project that work very well, but I wanted to expand the original code (found here: Lightweight CSV reader for Unity | Brave New Method ).
This is my code

`using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Main: MonoBehaviour {

void Start () 
{
}

void OnMouseDown()
{
	List<Dictionary<string,object>> data = CSVReader.Read ("test");
	for(var i=0; i < data.Count; i++) 
	{
		print ("id " + data*["id"] + " " +*

_ "message " + data*[“message”]);_
_
}_
_
}_
_
void OnMouseOver()_
_
{_
_
print (gameObject.name);_
_
}_
_
}_
_
`*_
At the moment this code prints the whole CSV content, but I want it to pick randomly a string, each time I execute it. I’ve made some research and tests, but invane, maybe because I’m not a programmer.
I think I should use the Random.Range method, but I don’t know how to refer to the strings inside the CSV.
I strongly hope that anybody here could help me :slight_smile:

Well, the for loop is the reason why you see the whole content, because the print command is called for every (valid) value of i. If you want only the content for a certain entry, then remove the for loop and call the print function for just a certain i value (set i to the value you want). If you want a random value, set i to a random value:

int i = (int)Random.Range(0, data.Count-1);

The cast to integer (int) is necessary because Random.Range returns a float value, but indices like i must always be some integer.

By the way: It would be more efficient and clean to read the CSV file just once and store the content, if you want to access it multiple times. But this requires some programming knowledge and for small CSV files there should be no performance problem if you don’t do it.

Oh, thank you so much! This is a very small project, so the CSV shouldn’t be too big. Thanks again!