New Random().Next(Apple,Banana,Pear) possible?

Hi Guys,

This gives me a random number between 1-99.
new Random().Next(1,99)

Possible to get this working with strings ?
new Random().Next(Apple,Banana,Pear)

I appreciate one is integer and the other is string.
Can quite easily achieve by doing it in a list where I can assign a random number between 0-2 (zero index base) then read list item with this random number giving me a random fruit.
Just wondering if its possible with new Random().Next(Apple,Banana,Pear)

No big deal :grinning:

dont think you can do it directly

like you said there are alternatives like this

ListVar(new Random().Next(0, ListVar.Count))
1 Like

WE suggest use Mod within the random to getan better distribution of randoms

Listvar( new random().next() Mod listvar.count())

1 Like

Hi @MikeC ,

Welcome to the community !

Random function is primarily a method of Integer class. It wont be able to support List of Strings.

Hope this helps.


1 Like

Hey Peter, I have actually noticed the randoms at the lower end of the scale, as in a random number from 1-5, 5 rarely comes up so Mod makes sense.

Thank you.

ListVar(new Random().Next(0, ListVar.Count-1))

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.