Question

This homework is an approach to generating random numbers. In this technique a seed value is...

This homework is an approach to generating random numbers. In this technique a seed value is used to construct a new (seemingly random) value in the following manner:

 The seed, s, is written down in n-bit binary.

 Several bit positions, called taps, are used to generate a feedback bit. Bit n-1 is always one of the taps.

 The feedback bit, f is the exclusive-or of the tap bit values

 The seed is shifted to the left one bit, dropping the leftmost bit. The rightmost bit is set to f.

In this manner, a seed is transformed into a new (hopefully different!) value which may be used for whatever purpose is desired. This value can also serve as the next seed. If the taps are picked appropriately, a large number of unique values (ideally 2n -1) are generated before the original seed reappears. (This technique has one obvious deficiency that will not concern us: a seed of 0 will generate 0 and lock up the mechanism.)

For example, using a nibble:

User inputs seed of 6= 0110

User enters the taps 3 and 2. (These are the bit numbers, remember that BIT n-1 is always used so bit 3 would be used even if the user did not enter it.)

0110 the feedback is bit3 xor bit2, f = 0 xor 1= 1

Shift the bits to the left dropping the leftmost bit and the rightmost bit is set to f, which equals one. 1101=13.

The random number is now 13.

If we looped with 13 now being the seed.

1 xor 1 = 0 1010=10.

10 would be the next random number.

Write a C program:

1. Use a command line argument for an unsigned integer for the seed and validate that this is a positive integer. End program if not a valid number. (Remember that it is a string and you must convert it to an integer.)

2. Prompt the user for the taps, end with a -1. Validate that the taps (bit numbers) are between 0 and 31. End the program if invalid.

3. Prompt the user for the number of random numbers that they would like to generate. Must be a positive integer greater than 0. If invalid ask user again to enter the number again.

4. Output the random numbers generated to a file “random.txt.”

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
This homework is an approach to generating random numbers. In this technique a seed value is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • Write the Code in C program. Create a random password generator that contains a user-specified number...

    Write the Code in C program. Create a random password generator that contains a user-specified number of characters. Your program should prompt the user for the desired length of the password. Length of password: To create your password, use the random number generator in the stdlib.h C library. To generate random numbers, you will need the srand() and rand() functions. srand(seed) is used to "seed" the random number generator with the given integer, seed. Prompt the user for the seed...

  • ​Declare an array with 1000 elements of type int Then in a loop generate 1000 random numbers and assign one to each element in the array The random numbers should be between 1 and 50 Then, prompt the user to enter a number, store this number in a local

    Rules to follow are:Declare an array with 1000 elements of type intThen in a loop generate 1000 random numbers and assign one to each element in the arrayThe random numbers should be between 1 and 50do not use rand or srand, use code is providedThen, prompt the user to enter a number, store this number in a local variable, the number should be safety checked using the GetInteger() functionThen, iterate through the array and determine how many times the user's...

  • CNIT 105 In Lab10 Due: By the end of your lab session OBJECTIVES: bitwise operations main...

    CNIT 105 In Lab10 Due: By the end of your lab session OBJECTIVES: bitwise operations main () function: 1. Declare an int variable, name it number. 2. Prompt the user to enter a whole number- read it into the variable. Validate the range in a loop. Valid range is 20 to 200 both inclusive . 3. Display the number to the screen (base 10) 4, Display the number in hexadecimal (Use %X) 5. Display number to the screen -It will...

  • Write a Java program that generates an array of Fibonacci numbers. Specifications: The program -Fills a...

    Write a Java program that generates an array of Fibonacci numbers. Specifications: The program -Fills a one-dimensional array with the first 30 Fibonacci numbers using a calculation to generate the numbers. Note: The first two Fibonacci numbers 0 and 1 should be generated explicitly as in -long[] series = new long[limit]; //create first 2 series elements series[0] = 0; series[1] = 1; -But, it is not permissible to fill the array explicitly with the Fibonacci series’ after the first two...

  • In C... Write a program to simulate a pick-5 lottery game. Your program must generate and...

    In C... Write a program to simulate a pick-5 lottery game. Your program must generate and store 5 distinct random numbers between 1 and 9 (inclusive) in an array. The program prompts the user for: an integer random seed five distinct integers between 1 and 9 (which are stored in another array) The program then compares the two arrays to determine if they are identical. If the two arrays are identical, then the user wins the game. otherwise the program...

  • Write a program in C++. You need everything everythihng given You will create a function that...

    Write a program in C++. You need everything everythihng given You will create a function that validates input. It should accept only non-negative integers. If the input is incorrect the function should throw an exception. The exception will not be caught in the function. You will create a function that reads in 2 integer values. One is a number that will be raised to the power of the second. So if 5 and 6 are entered the result would be...

  • I need to create a bit of code for javascript which I can have random numbers...

    I need to create a bit of code for javascript which I can have random numbers generate with a certain amount of digits set by the user. and ask the user how many times they want this to happen. For example The user says they want a number with 4 digits (any number between 0 - 9999) and the user can input if they want to add, subtract, multiply, divide, or make it random 2 random numbers are generated. First...

  • Write a program in C to generate random numbers. The program recieves 4 items on activation...

    Write a program in C to generate random numbers. The program recieves 4 items on activation through argv: 1. Name of the data file 2. Number of items for program to generate 3. Range of numbers 4. Seed of the random number generator Example run: ./rand datafile.txt 20 1000 3127 Program must convert all numbers to ints using atoi(), must save all parameters into variables, opens the data file to write the random numbers into it, program loops to generate...

  • Use linear congruential generator with seed value 31, a = 11, c = 17, m =...

    Use linear congruential generator with seed value 31, a = 11, c = 17, m = 100 and inverse transform technique to generate: 10 continuous uniform random variates on interval [1; 10];                                             [5] 10 exponential random variates with parameter λ = 3.                                                     [2] It is suspected that the generated random numbers (Ri) are autocorrelated, since an observer notices that every 4th number starting (but not counting) from the 1st number (i.e. i = 1) is larger...

  • For this assignment, write a program that will generate random numbers in the range of 50-100...

    For this assignment, write a program that will generate random numbers in the range of 50-100 and count how many fall into particular ranges. Processing: The program should first seed the random number generator. This is done one time in the program. Use srand(0). Next, generate and display a series of 10 random numbers between 50 and 100. There are several ways to ensure that a random number falls between 50 and 100. One possibility is to use the following...

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
ADVERTISEMENT