Pick random element: Difference between revisions
Content deleted Content added
added c# solution |
|||
Line 58:
Random, randint, 1, %list0%
MsgBox % List%randint%</lang>
=={{header|C}}==
<lang C>#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(){
char array[] = { 'a', 'b', 'c' };
srand( time( 0 ) );
printf( "%c\n", array[ rand() % 3 ] );
return 0;
}</lang>
=={{header|C#}}==
<lang C>using System;
using System.Collections.Generic;
class RandomElementPicker {
static void Main() {
var list = new List<int>(new[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
var rng = new Random();
var randomElement = list[rng.Next(list.Count)];
Console.WriteLine("I picked element {0}", randomElement);
}
}
int main(){
|