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...
Please, write this code in c++. Using iostream and cstring library. Write a function that will...
Please, write this code in c++. Using iostream and cstring library. Write a function that will delete all words in the given text that meets more that one time. Also note than WORD is sequence of letters sepereated by whitespace. Note. The program have to use pointer. Input: First line contains one line that is not longer than 1000 symbols with whitespaces. Each word is not longer than 30 symbols. Output: Formatted text. example: input: Can you can the can...
Please, write code in c++. Using iostream and cstring library Write a function that will find...
Please, write code in c++. Using iostream and cstring library Write a function that will find and return most recent word in the given text. The prototype of the function have to be the following void mostRecent(char *text,char *word) In char *word your function have to return the most recent word that occurce in the text. Your program have to be not case-sensitive(ignore case - "Can" and "CAN" are the same words) Also note than WORD is sequence of letters...
Please write code in c++ using iostream library. Also you can use any string library. Create...
Please write code in c++ using iostream library. Also you can use any string library. Create structure plane with the following: 1)plane's ID[int type] 2) location[char*] 3) departure time[char*] Your task is to find the plane with the smallest departure time for the selected city. Pointer, dynamic array and structures have to be used in this code. Input: NOTE: It's just an example of input, you should write code generally for any inputs. First line contains n(0 < n <...
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.
Please write code in c++ using iostream library. Write a function bool cmpr(char * s1, int...
Please write code in c++ using iostream library. Write a function bool cmpr(char * s1, int SIZE1, char * s2, int SIZE2) that compares two strings. Input Input contains two strings. Each string is on a separate line. example: aqua aqua Output Output YES if given two strings are the same or NO otherwise. YES
Gauss Jordan elimination using python for a 2d list (3x3) without using any library. Thanks
Gauss Jordan elimination using python for a 2d list (3x3) without using any library. Thanks
How to create a divide function in (Dr Racket) programming language without using the built in...
How to create a divide function in (Dr Racket) programming language without using the built in function " / " ?
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT