Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
C Pointers Experiment (So bad don't use)
#include <stdio.h> #include <math.h> /* Keep in mind I have no clue what I'm doing lol I probably look so stupid rn lmaooooo -----DO NOT USE THIS FOR A RANDOM NUMBER GENERATOR!!!!------ NOTES: I tried "clearing" the seed variable to generate a new address but from doing some intense research, baseically going on stack overflow and some other forums, there seemed to be no solution to this problem, for the c language at least.o EDIT: I may have come up with a solution, I'll try it out later though. Aside from the first major problem, numbers seem to repeat quite a lot. However, this seems to become less of an issue with higher prime numbers. I will need to experiment a bit more. This is my first time experimenting with pointers so I decided to make a random number generator just to understand how pointers work. I did not expect to face this many problems, like usual when I'm learning something new, with creating a random number generator. OBSERVATIONS: When viewing the adress number, it could always divide into 4. My solution was to divide by a prime number, as those will always have remainders when you divide them, I think... */ int random(int x, int y){ unsigned int prime_number = 167; // Higher number = better results? int randNumber = 0; // Created a var just to visualize this better int seed = 1; // Creating a variable to generate a new ptr address int *aptr = &seed; // Gets the address of "seed" in memory (this is really the seed) randNumber = x + (abs(aptr)/prime_number)%y; // dividing by a prime number (may help with generating a more percise rnd number???) return randNumber; } int main(){ for (int i = 0; i <= 10; i++){ printf("%d\n", random(0, 100 + i)) ; // My hacky solution to generate more rnd numbers } }
run
|
edit
|
history
|
help
0
18BCE2182 ASSESS_1 Q2-3
Array Struct, Call-By-Reference, Malloc, Free, Init, Destroy ... Example
static int account
Spring 2017 Project 2 v1.2
Estrutura
guia 4 terminada
recursive fundamentos
MinMaxArray
Hello
tremendo codigaso ayudantia