Hi,
I am trying to randomly pick a string from a queue of strings and then pass that string on to a function call. Can I do that using randomize()? I am new to OVM , I am doing something similar to below , please let me know if that is correct:
e.g
dummy_class arg;
string dummy_names= {“abc”, “efg”,“xyz”, “mno”};
arg= new(std::randomize(dummy_names), 1);
obj.func(arg);
So the randomize function should return me the index of the randomly chosen queue member if I can use it as above?
Also can someone point out where to find documentation on this?
Thanks in advance
A couple of problems with your code
string dummy_names= {"abc", "efg","xyz", "mno"};
Is legal, but dummy_names is not a queue; it is just a simple string and you have concatinated 4 string literals into a single string It is the same as
string dummy_names= "abcefgxyzmno"};
Your other problems are that the randomize function only randomizes integral variables, not string variables, and that randomize returns non-zero on a successful randomization, and zero on failed randomization. It never returns the value of the randomized variable.
You have two options after you fix the queue declaration. You can either shuffle the queue and pick the first or last element of the queue, or you can pick a random index value
string dummy_names[$]= {"abc", "efg","xyz", "mno"};
...
arg = new(dummy_args[$urandom_range(0,dummy_args.size()-1), 1);
//or
dummy_names.shuffle();
arg= new(dummy_names[0], 1);
q.shuffle() is the simplest way to achieve this.
In reply to dave_59:
Thanks a lot Dave. That queue thing was a typo. will review my code better from next time onwards before posting.
In reply to Sushrut Veerapur:
Thanks a lot Sushrut