I'll do your intro to CS assignments bc I'm bored

I'll do your intro to CS assignments bc I'm bored

Attached: Snippet00-1024x608.png (1024x608, 209K)

Other urls found in this thread:

en.wikipedia.org/wiki/Linear_congruential_generator
stackoverflow.com/questions/22137985/generate-random-number-from-random-bits
en.wikipedia.org/wiki/Rejection_sampling
twitter.com/SFWRedditVideos

nevermind figured it out

Do my data structures

Graph Algorithms

Attached: B1E22340-A80E-42E0-9EFE-D8F1E2F00BC5.png (750x1334, 363K)

I'm supposed to write a random range function that gives a random number between A and B. Each number must appear with equal probability. The only library function I'm allowed to use is random_bit() which just randomly returns 1 or 0.

HELP

Attached: 1549341530705.jpg (200x313, 10K)

binary number ^-1 ezpz

int ura_faget(void) {
return 0xA + random_bit();
}

What? Oh sorry also I meant random integer

>random
>each number must appear with equal probability

I hope you aren't paying for this "education"

just append a bunch of random bits together and then convert it to a decimal number snd raise it to the power of -1 and then do whatevery you want with it
There's a real way to do it but that's the noob way

Yeah like I roll a die and I expect to see 1 2 3 4 5 and 6 with equal probability, what's wrong with that?

user

Attached: 1549331945167.jpg (1200x900, 119K)

I don't understand, how does that guarantee equal probability?

If you append 100 bits together, wouldn't the result be around 50 every time?

en.wikipedia.org/wiki/Linear_congruential_generator

The problem is the seed, does it need to be different random numbers each time the program is run?

Find the smallest number x that causes f(x) to halt or prove that no such number exists.
void f(long long x){
while(x!=1) {
x= x%2 ? 3*x+1 : x/2;
}
}

Thanks OP, I've been stuck on this for a while.

kill yourself

No I'm supposed to use random_bit() which is apparently a trusted source of true randomness. The assignment isn't to write a pseudo random number alg

int num = 0;
for (int i = 0; i

That isn't equal probability to each number though. My professor talked about the problem in class and said this was wrong

1

stackoverflow.com/questions/22137985/generate-random-number-from-random-bits

I found this, but I don't really understand it.

6/10, made me chuckle.
Then again if anyone can solve the Collatz conjecture problem it's some user. Just look what we've done for superpermutations.

Key is to determine how many bits are necessary to generate between a and b without waste or bias, there are several methods to accomplish this

t. just read stack overflow

Calculate the nth Fibonacci number in linear time with regards to the bits of n

google "uniform distribution "

yes

OK dude, we have a Hill cipher with a key in (Z mod 26)^3, and the known plaintext and ciphertext

>plaintext : 2 17 24 15 21 14 6 17 0 15 7 24 0 13 3
>ciphertext : 8 11 21 19 17 13 14 3 25 1 1 17 3 2 19

what's the key?

this is one of those threads where 85% of the posts are absolutely braindead and retarded

if random_bit is truly random, then just append the generated bits together and use modulo & addition to move it into desired range; each number in the range will be equally probable

Why don't you just shut the fuck up about something you clearly have no clue about?

Wow those are some shitty questions, this is more math than algorithm in itself. The goal is just to play with the algorithm and data structure until you get it right ? I would have been so mad if my assignment looked like that.

t. took CS to "learn to make video games"

Attached: 1549332372795.jpg (680x691, 99K)

Proof?

No, my assignments were actual problem solving, not playing with algorithm. Same for tests, you had to prove that you understood how to solve a problem, not how to play with known algorithms.

I'll tell you the way I thought this through.
Think about what the problem would be like for specific A and B. Really, all you need is to generate an integer between 0 and B-A (inclusive), because you can then just add A and shift the range back up to [A,B].

For the sake of simplicity, let n = B-A. So we want to generate an integer from [0,n] uniformly at random. Again, we start with a simple case. What if n=1? Well, if use random_bit, then half of the time we'll generate 0, and half of the time we'll generate 1, so that works. What if n=3? Use random_bit twice (as some others here have suggested). The four possibilities are 00, 01, 10, 11, with equal probability, and each corresponds with one (integral) value in [0,n].

You can see that this works if we let n=7, and then use three random bits, and in general, if n is 2^k-1, it will take k random bits to generate a random int in [0,n].

But what if n is not 1 less than a power of 2? For instance, what if n=2, so we want to generate an int in [0,2], i.e. 0,1, or 2 - three possibilities. Well, we actually proceed the same way - we take as many bits as we need (rounding up), in this case, 2 (because 2^2 = 4 >= 3). For each integer we want a possibility of generating, we set it to correspond to exactly one of the binary numbers we are generating (00 0, 01 1, 10 2). And the difference is that for every binary number that is not mapped to a number in our desired range, we simply reroll.

So for the case n=2, we generate two random bits. If the bits == 00, return 0. If bits == 01, return 1. If bits == 02, return 2. Otherwise, generate two random bits again, and go through the process. That is, "reroll"

Those are actual problems. They're not really programming problems, but they are definitely computer science.

so the Stack Overflow solution reworded? cool

OK I'll give you a hint, you need to pick certain tuples out of the plaintext and make an invertible matrix out of them

>he thinks somebody's working on it

I have an annoying discrete math problem

a / (b + c) + b / (a + c) + c / (a + b) = 4

Sure they are, I just said that if my assignment looked like that I'd be fucking mad. I don't really know how it works in muttland but I already had my fill of theorical and boring shit in math / physics / electronics before I got into comp sci. So seeing an assignment like that just makes me think of all the useless shit they made us learn in math / physics.
And I think it's useless cause you never have to use it outside of classes.

t. Someone working on compilers

see

...

Are you American? Please be honest.

double rand_in _range(double a, double b){
return random_bit()*(a-b) + a;
}

Are YOU American? Please be honest.

Use binets formula

Probably, yeah. Easy problems tend to have easy solutions

He's probably an underclassman taking first or second year courses. I know that those classes often seem futile, but I think it's pretty clear, in retrospect, that people who can't even get past those topics will inevitably fail later on.

Also, computer programming is a very different topic than computer science. Furthermore, there is a huge difference between working on written CS homework vs programming homework. And there's also a big difference between programming homework and actually working on programming projects. Working on compilers is surely vastly different from taking a class in it.

Newfoundland

by the frig, aye's the bye that built the boat

it turns out just appending your random bits can give you random points between 0 and 2^n. So make the closest 2^n box around your range and then discard all the points outside of it.

en.wikipedia.org/wiki/Rejection_sampling

Here, it fills up a number, then constrains it between A and B.

Attached: Untitled.png (831x729, 28K)