Found your channel today and this was a great video to follow along to.
@NERDfirst3 жыл бұрын
Hello and thank you very much for your comment! Glad you like my work =)
@maratdavletov3803 жыл бұрын
Hello, i started to learn programming recently and i dont understand why you choose other language to write this function. Is python dont let you to write it using "for" function? I am trying to make .shuffle with "for" but i cant understand how to manage with repeating elements.
@NERDfirst3 жыл бұрын
Hello and thank you for your comment! The same can absolutely be done with Python - I chose C because it's a lower-level language that doesn't give us things like random.shuffle(). Of course, if you're already using Python then you can just call random.shuffle() directly, but the algorithm given here can be implemented in any language.
@Rumble_Ball3 жыл бұрын
Why not use the entire array index range for the new index? Only using indexes behind seems bad for the end of the array and is more computation.
@NERDfirst3 жыл бұрын
Hello and thank you for your comment! You could certainly do a fixed number of random swaps across the entire array, and you'd get a shuffled result too. My goal here was to make it fair for every element in that every index is considered once for the swap.
@Rumble_Ball3 жыл бұрын
@@NERDfirst but if your are realy unlucky you will always get the last index. And the more you process the higher the chance to get the last index as the possible numbers get reduced
@NERDfirst3 жыл бұрын
That's absolutely true! I'm not trying to guarantee that the list does gets shuffled. I mean, after all, getting the exact same list back is a possible result, and if my probability and statistics isn't too rusty, it's equally likely as getting any other combination. Having said that, I can't confirm that my technique here gives rise to all possible combinations in equal probability!
@JohnSmithhh2 жыл бұрын
I thought you will explain how rand() method works :)
@NERDfirst2 жыл бұрын
Hello and thank you for your comment! Anything about rand() you'd like me to clarify?
@lawrencedoliveiro91043 жыл бұрын
4:57 rand(3) returns integers up to RAND_MAX which, as you noticed, can be quite small man7.org/linux/man-pages/man3/rand.3.html . That man page recommends using something like random(3) instead.
@NERDfirst3 жыл бұрын
Hello and thank you for your comment and for sharing! This is a toy example so in fact RAND_MAX is more than enough for such an application. But perhaps someone else doing more complex random number generation in C might find this useful!
@lawrencedoliveiro91043 жыл бұрын
If you want something more like cryptographically strong random or pseudorandom numbers, then perhaps use /dev/urandom or /dev/random linux.die.net/man/4/urandom .