Amazon Interview Question for Software Engineer / Developers


Country: United States




Comment hidden because of low score. Click to expand.
0
of 0 vote

public class PRandom{
 int random_seed;
 void seed(int random_seed) {
     this.random_seed = random_seed; 
 }
 int rand() {
     random_seed = random_seed * 1103515245 +12345;
     return (int)(random_seed / 65536) % 32768;
 }
}

You should initially seed the psudo random generator with a number such as the current time since that will be different at every runtime.

Otherwise just hook up a geiger counter to the computer and look at the radioactive decay, that is truly random.

- luckless March 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

otherways to find the initial random seed : 1. time of day 2. GetPid

- Anonymous March 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

An example of a simple pseudo-random number generator is the Multiply-with-carry method invented by George Marsaglia. It is computationally fast and has good (albeit not cryptographically strong) randomness properties (note that this example is not thread safe):[6]
m_w = <choose-initializer>; /* must not be zero */
m_z = <choose-initializer>; /* must not be zero */

uint get_random()
{
m_z = 36969 * (m_z & 65535) + (m_z >> 16);
m_w = 18000 * (m_w & 65535) + (m_w >> 16);
return (m_z << 16) + m_w; /* 32-bit result */
}

- sunny April 02, 2012 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More