Skip to content
Sign upLog in
← Back to Community

How to make a random selection from a list of options

Profile icon
[deleted]

How do you make a random selection from a list of numbers or characters in C

Comments
hotnewtop
Profile icon
Coder100

Hi! Try something like this:

int arr[3] = { 1, 2, 3 }; int index = rand() % 3; // rand() % [array length] int out = arr[index]; // a random selection!
Profile icon
PattanAhmed

@ImmaEatYouMan
Hi,
You can check this Beautiful Website as it is cutting straight towards your question.
Click here

Hope this helps
Please mark my answer if this helps.

Profile icon
Coder100

Hi, that's C#

@PattanAhmed

Profile icon
PattanAhmed

@Coder100
He needs that only!

Profile icon
Coder100

he says C not C#

@PattanAhmed

Profile icon
PattanAhmed

@Coder100
Oh Ok!

Profile icon
PattanAhmed

@Coder100
Bur aren't two same?? :/

Profile icon
Coder100

nope they are 2 different languages!

@PattanAhmed

Profile icon
PattanAhmed

@Coder100
Cool, I heard it for the first time! :)