hi i would like u to tell me if i can make a random function to choose between four numbers and only them(-1 , 1 , -10 ,10)
james85
0
Newbie Poster
Recommended Answers
Jump to Post/* say numbers are 2,8,15,51 so upperLimit=51 & lowerLimit=2 */ int num; do num=rand((51-2)+1)+2; //This I deliberately did to denote uLimit & lLimit while(num!=n1 && num!=n2 && num!=n3 && num!=n4);
rand(x) will always return a number from 0 to (x-1).
Jump to Posthi i would like u to tell me if i can make a random function to choose between four numbers and only them(-1 , 1 , -10 ,10)
Yes, you can. Quite easily, in fact:
int a[] = { -1, 1, -10, 10 }; int choice = …
All 7 Replies
nbaztec
45
Posting Pro in Training
james85
0
Newbie Poster
nbaztec
45
Posting Pro in Training
Narue
5,707
Bad Cop
Team Colleague
nbaztec
commented:
Thanks for correcting me. :)
+1
nbaztec
45
Posting Pro in Training
Narue
5,707
Bad Cop
Team Colleague
nbaztec
45
Posting Pro in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.