How do i generate a random number between 2 bodies | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How do i generate a random number between 2 bodies

As above; I wanna make a simple higher/lower card game and i just dont know how to generate a random number

23rd Dec 2022, 4:03 PM
werewolfdragon
werewolfdragon - avatar
7 Answers
+ 3
Agreed Tina 🕊🇺🇦🇮🇷 . That was a snippet from my help code from other question. Completely it would have looked like this: https://code.sololearn.com/cjqnVOICZkkg/?ref=app
26th Dec 2022, 9:59 AM
JaScript
JaScript - avatar
+ 3
#include <iostream> #include <cstdlib> using namespace std; // generate a random integer number from b up to e int intRand( int b, int e) { double r = e - b + 1; return b + (int)(r * rand()/(RAND_MAX+1.0)); } // Next time you need show your attempt with a question.
23rd Dec 2022, 4:24 PM
JaScript
JaScript - avatar
+ 2
JaScript great! perhaps adding a random seed makes it perfect.
23rd Dec 2022, 4:32 PM
Tina
Tina - avatar
+ 2
JaScript your random sequence is always the same pattern. run the code multiple times. https://code.sololearn.com/cP2X15VoVPQS/?ref=app
25th Dec 2022, 7:04 AM
Tina
Tina - avatar
+ 1
Tina 🕊🇺🇦🇮🇷 would you like to show us, how can mentioned code be made perfect?
24th Dec 2022, 8:40 PM
JaScript
JaScript - avatar
+ 1
I have learned, that i dont know enough for this question yet. But thats okay
2nd Jan 2023, 3:23 PM
werewolfdragon
werewolfdragon - avatar
+ 1
Or maybe tina is just trying too hard when i need an introductory answer
2nd Jan 2023, 3:24 PM
werewolfdragon
werewolfdragon - avatar