Question

C++ 1) Write a random number generator that generates random integers from -10 to 10. 2)Write...

C++
1) Write a random number generator that generates random integers from -10 to 10.

2)Write a random number generator that generates random integers from 0 to 10.

Also can you explain how does it work if possible. Thank you.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1)

#include <iostream>
#include<stdlib.h>
#include<time.h>
using namespace std;

int main()
{
int n,x;
srand(time(NULL)); //It is used to initialize the pseudo random number by taking time as an argument
cout<<"Enter How Many Numbers"<<endl;
cin>>n;
cout<<"The Random Numbers Generated are"<<endl;
for(int i=0;i<n;i++)
{
x=rand() % 22 -10 ; // This will display Numbers from -10 to 10
cout<<x<<endl;
}

return 0;
}

2)

#include <iostream>
#include<stdlib.h>
#include<time.h>
using namespace std;

int main()
{
int n,x;
srand(time(NULL)); //It is used to initialize the pseudo random number by taking time as an argument
cout<<"Enter How Many Numbers"<<endl;
cin>>n;
cout<<"The Random Numbers Generated are"<<endl;
for(int i=0;i<n;i++)
{
x=rand() % 11 ; // This will display Numbers from 0 to 10
cout<<x<<endl;
}

return 0;
}

Add a comment
Know the answer?
Add Answer to:
C++ 1) Write a random number generator that generates random integers from -10 to 10. 2)Write...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C# prograaming language 1. write a program that generates 10,000 random integers in the range of ...

    c# prograaming language 1. write a program that generates 10,000 random integers in the range of 0-9 and them in binary search tree. 2. use any sort algorithm (insertion, bubble, quick...) to display a list of each of the integers and how many times they appear. 3. at last, add ruction to the BinarySearchTree class that count the number of edges in a tree. Write a program that generates 10,000 random integers in the range of 0-9 and store them...

  • Write a C program that generates one hundred random integers between 0 and 9 and displays...

    Write a C program that generates one hundred random integers between 0 and 9 and displays the count for each number. (Hint: Use rand()%10 to generate a random integer between 0 and 9. Use an array of ten integers, say counts, to store the counts for the number of 0’s, 1’s,…..,9’s.)

  • Write a C++ program that generates a random number from 0 to 9. It will then...

    Write a C++ program that generates a random number from 0 to 9. It will then prompt the user to guess the random number it generated. Your program stops if the user guesses the right number. (Use the cout function to display the random number the computer generates so that you can determine if your code actually works). SAMPLE OUTPUT Random number = 8 Guess a number in the range [0,9]: 1 Too low Guess a number in the range...

  • Part 2 -Arrays We can use the Math.random method to generate random integers. For example, Math.r...

    Please write a JAVA program according to following requirement. Thanks Part 2 -Arrays We can use the Math.random method to generate random integers. For example, Math.random () generates a random integer greater than or equal to 0 and less than 1. The expression Math. random) 6generates random numbers between 0 and 5, simulating the throw of a die. In this lab assignment, you will use an array to test whether the random generator is fair; that is, whether each possible...

  • Write a program in python that generates X random integers Num. Num is a random number...

    Write a program in python that generates X random integers Num. Num is a random number between 20 to 50. X is a random number between 10 to 15. Calculate and show the Smallest, Largest, Sum, and Average of those numbers. You are not allowed to use Python functions sample(), min(), max(), average(), sort(), sorted()!! HINTs: to find Smallest.... 1) X is a random number between 10 to 15... for example 11...this determines how many times the loop will happen...

  • Write a C++ program that generates twenty five random integers between 0 and 24 and display the sum of even integers.

    (C++)Write a program that generates twenty five random integers between 0 and 24 and display the sum of even integers. (Hint: Use rand()%25 to generate a random integer between 0 and 24. Use an array of 25 integers, say num , to store the random integers generated between 0 and 24.)

  • Write a program that generates an array of one hundred random integers between 0 and 9...

    Write a program that generates an array of one hundred random integers between 0 and 9 and displays the count of each number. C programming

  • C language Write a program that generates 20 random integers (ranging in between 0 to 100)...

    C language Write a program that generates 20 random integers (ranging in between 0 to 100) and outputs all the even random numbers.

  • java 1. Write an application that generates n random integers in the range provided the user....

    java 1. Write an application that generates n random integers in the range provided the user. Use method genrate Even to generate even numbers only and generateOdd to generate odd numbers void generateOdd(int n, int r1, int r2); void generateEven(int n, int r1, int r2); Sample run: How many integers you have?5 What are your number ranges? 3 10 The generated even numbers are 6 4 8 10 6 The generated odd numbers are 37 9 35

  • Q1. 4 points You've recently bought a "random number generator (RNG) from an online retailer. Everytime...

    Q1. 4 points You've recently bought a "random number generator (RNG) from an online retailer. Everytime you push a button of the RNG, it generates a nine-digit long random number (number consisting of random nine-digits from 0-9). How many times do you need to push the button in order to guarantee that at least two of the numbers generated by the RNG have the first 3 digits common? Fully evaluate the result TOUR OF ACCOUNTING OVER HERE LE HAVE OUR...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT