Question

In: Computer Science

in c++, without using any built-in random library already exist, instead,write your own function to generate...

in c++, without using any built-in random library already exist, instead,write your own function to generate random char from a list of:

10 letters T

10 letters H

10 letters A

10 letters N

10 letters K

Solutions

Expert Solution

Generally, we use rand() function to generate random number in given range.

Here, we are not allowed to use any built-in random library.

Let's think differently to solve task alloted to us.

What is else which is randomly alloted in program?...

There are many things which are randomly allocated to program while running like Processor, Turn, position in queue, memory etc..

We could easily access memory address using pointer . Yes we could use pointer to generate random within given range.. Let's check it

Here is a code snippet which will print random character from list of characters..

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string t(10,'T');
    string h(10,'H');
    string a(10,'A');
    string n(10,'N');
    string k(10,'K');
    string mylist=t+h+a+n+k;
    int*p=new int;  ///Random memory allocated to p. We will use memory address to generate random integer
    int myrand;
    myrand=(int)p%mylist.size();    ///limiting range of integer to size of list
   /// cout<<myrand; This line will print random integer between 0-50
    cout<<"Random Character Generated is : "<<mylist[myrand];
}

OUTPUT'S SCREENSHOT

1.

2.

3


Related Solutions

C Program: Write your own stringLength function (without calling a pre-written library function) that returns the...
C Program: Write your own stringLength function (without calling a pre-written library function) that returns the length of the string argument in characters, not including the terminating ‘\0’ character.   Write four versions of a void printString function (i.e., printString1, printString2, etc) each of which prints its string argument character-by-character but using the following techniques: printString1: array indexing printString2: pointer/offset with the array name as a pointer, printString3: pointer indexing, and printString4: pointer/offset with a pointer Write a void function called...
Write a function that will generate an array of random numbers. It needs to:
DO IN C++Write a function that will generate an array of random numbers. It needs to:Take 3 integers as parameters-The first is the minimum value-the second is the maximum value-the third is the size of the new array-create a dynamically allocated array of the correct size-generate a random number (between min and max) for each element in the array-return a pointer to the arrayCreate a main() function that tests the above function and displays the values in the random array.
Write a function to generate random variates from a Lognormal(mu, sigma) distribution using a transformation method,...
Write a function to generate random variates from a Lognormal(mu, sigma) distribution using a transformation method, and generate a random sample size of 1000 in R. Compare the histogram with the lognormal density curve given by dlnorm function in R.
Please write down your own personal views of Walmart – without reference to any research. What...
Please write down your own personal views of Walmart – without reference to any research. What are they doing well and what are they doing poorly in your view, or what are your perceptions of the company? Create a two-column table, similar to a ‘T’ chart, to separate the pros and cons and discuss either Wayne Visser’s views of what makes Walmart an important study in terms of sustainability and scalability (chapter 8), or you may also use the internet...
Please, write code in c++. Using iostream and cstring library. Your friend is the person who...
Please, write code in c++. Using iostream and cstring library. Your friend is the person who does not like any limitations in the life. And when you said to him that it is totally impossible to work with integer numbers bigger than 4 294 967 296 in C++ he blamed you in time-wasting during the university study.So to prove that you hadn't waste 2 months of your life studying C++ in university you have to solve this issue. Your task...
The language is MATLAB Write a function that will generate three random integers, each in the...
The language is MATLAB Write a function that will generate three random integers, each in the inclusive range from 10 to 80. It will then return a string consisting of the three integers joined together, and also a character vector consisting of the three integers joined together. For example, if the random integers are 11, 29, and 76, the string that is returned will be "112976" and the character vector that is returned will be '112976'. I'm really confused on...
Without using google or encyclopedia, in your own words write a definition for each: 1. Finance...
Without using google or encyclopedia, in your own words write a definition for each: 1. Finance 2. Bonds 3. Financial Assets 4. Financial Instruments 5. Securitized assets
Using c++, write a program that will display your name as a void function then will...
Using c++, write a program that will display your name as a void function then will perform the following by user-defined functions: a. to compute for the sum of two numbers (n1, n2) using function.
-Write in C++ -Use Char library functions Write a function that accepts a string representing password...
-Write in C++ -Use Char library functions Write a function that accepts a string representing password and determines whether the string is a valid password. A valid password as the following properties: 1. At least 8 characters long 2. Has at least one upper case letter 3. Has at least one lower case letter 4. Has at least one digit 5. Has at least on special character
Write a program that uses a custom function to generate a specified number of random integers...
Write a program that uses a custom function to generate a specified number of random integers in a specified range. This custom function should take three arguments; the number of integers to generate, the lower limit for the range, and the upper limit for the range. Values for these arguments should be entered by the user in main. The custom function should display the random integers on one line separated by single spaces. The function should also report how many...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT