CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Created by ☀Brains
//write a code that generates random numbers between a range without usin random library
#include <iostream>
#include <ctime>
using namespace std;
int myrand(int a,int b){
time_t now=time(0);
char* brains=ctime(&now);
int avr=(brains[18]*998)%b;
if(avr<a){
avr+=a;
}
return avr;
}
int main() {
cout<<myrand(1,5)<<endl;
cout<<myrand(2,8)<<endl;
cout<<myrand(0,8)<<endl;
cout<<myrand(4,8);
return 0;
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run