![]() Each time you find a number you could reduce your search space by one so (using non primitives): while(myArrayList.size()>1) However if you assume that the getnum50 is more expensive than anything you can write you could reduce the number of getnum50 that you call while filling in the second half of the list. You could reduce a couple of ways one the fits into your current answer fairly will is as follows: while(n = 1) Your problem us that if you are toward the end of the list you will have to generate lots of random numbers to get a number in the couple of spots left. Separate numbers by space, comma, new line or no-space. If omitted a unique list of random numbers is generated each time you call the function. seed: Optional A numeric value used to seed the random number generator. count: The number of random values to generate. Generate numbers sorted in ascending order or unsorted. Returns a list of random numbers between 0 and 1, given the number of values to generate and an optional seed value. Select odd only, even only, half odd and half even or custom number of odd/even. I could not answer.So please give me proper answer for the question? How will I optimize my above code? Lets you pick 10 numbers between 1 and 100. ![]() He asks me to optimize the code so as to significantly improve the average case. You can then write down these selections, or copy them into your own applications. When you click the RANDOMIZE button, your selections will be dispayed. You can also choose how many items should be drawn from the list. In worst case scenario it would be infinity and tens of thousand in average case. Type or paste in your list of items, which should be separated by either a LINE or COMMA. While it was accepted in that round, in the next round the interviewer tells me that getnum50() is a costly method and even in best case scenario I have to call it twice for every number generated. N=1 //to indicate which random number is generated ("Generating random numbers in the range 1-100:") ("Length of array number100 is:"+number.length) Int n=new int //array to store which random numbers are generated Int number=new int //To store numbers in random order I wrote some code which was showing correct output. Part 2: Go Be patient It may take a little while to generate your passwords. The passwords will not contain characters or digits that are easily mistaken for each other, e.g., ‘1’ (the digit one) and ‘l’ (lowercase L). You cannot use any other random generator function except Each password should be characters long (minimum 6, maximum 32). ![]() You may call getnum50() any number of time to get random numberįrom 1 to 50 but try to make the code optimised. List should beĬompletely random i.e., all numbers have equal probability There should be no pattern in the numbers listing. Every number should be printed exactly once. You cannot use any other random generator. ![]() That this function is quite resource intensive. You can call this function as many times as you want but beware.Integer which is one random number from 1-50. You are given a predefined function named getnum50() which returns an. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |