Buckys C++ Programming Tutorials - 27 - Random Number Generator

  Рет қаралды 609,761

thenewboston

thenewboston

Күн бұрын

Пікірлер
@andrewlozano9473
@andrewlozano9473 8 жыл бұрын
I've been watching your C and C++ tutorials for some time now. When I don't fully understand something from my programming books, your videos are the go to videos to complement what I'm currently learning. Thank you!!
@Scottmilton1favs
@Scottmilton1favs 11 жыл бұрын
cout
@Scottmilton1favs
@Scottmilton1favs 11 жыл бұрын
Yeah, me too. Good video. :-)
@saltyman7888
@saltyman7888 11 жыл бұрын
std::cout
@rohinp784
@rohinp784 10 жыл бұрын
Anonim Vere-Casper ;
@gamingwithus_yt5109
@gamingwithus_yt5109 5 жыл бұрын
return 0;
@shalinisahnimankatalia5305
@shalinisahnimankatalia5305 5 жыл бұрын
@@gamingwithus_yt5109 }
@thenewboston
@thenewboston 13 жыл бұрын
@BrixXSM haha i name most of my files and classes foods. mostly whatever im in the mood for when i make the file
@MrAnonymousCitizen
@MrAnonymousCitizen 11 жыл бұрын
I am know I am a bit late, but this also goes for anyone having the problem. In order to actually get a random number (I don't know why it defaults to 41 if you don't do this.) You must call srand() and give it a time. NULL gives you a random number, otherwise it uses system time. So in your main loop type: srand(time(NULL)); Hope I helped! :D
@atharvdeshpande5408
@atharvdeshpande5408 4 ай бұрын
i know this is super random but its been 10 years since you commented, what did you end up doing in life lol, did you continue programming?
@jasonjjj27
@jasonjjj27 9 жыл бұрын
Thank you so much for your video series, I'm in a c++ online class, so everything I have to learn i have to read from this huge complex book, watching your videos is helping so much. You speak clearly and explain the concepts behind it well. Thank you
@geml1n
@geml1n 9 күн бұрын
Bucky, I seriously cannot thank you enough for these videos. Our professor links all of your videos that are relevant to the lecture and I never thought I would really use them...until today. The day of the final. I am wanting to be a mortican, not a coder but I am 80% complete with my degree, so i HAVE to finish it. It is hard to push yourself to complete something you don't even need/want anymore. I could not grasp c++ anymore the way I used to. Your videos actually make sense to me and I may have a shot of passing this class again. Thank you for what you do Bucky. Sorry for all the typos. All the best, A very sleep deprived, failing college junior
@SeRbianPlayingGames
@SeRbianPlayingGames 10 жыл бұрын
if any of you guys want a formula for making random numbers from like 2 to 24 it goes like this(at least what i came up with): x+(rand()%(y-x+1)); x is the starting number, y is the ending number
@JohnnyRelentless
@JohnnyRelentless 7 жыл бұрын
It's just (rand()%22)+2. You just add whatever you want you want your lowest number to be, and you subtract that number from the maximum.
@BruceBmk
@BruceBmk 7 жыл бұрын
NO seRPg is correct your method wouldn't work for bigger numbers say your Min was 1723 Max 1863 Your random numbers would run from 1723 to 1862
@gurindersingh614
@gurindersingh614 7 жыл бұрын
2+(rand()%24)
@bekiteru7015
@bekiteru7015 Жыл бұрын
you rock, how did u come up with this
@ethannguyen3840
@ethannguyen3840 4 жыл бұрын
Sitting in class for 1 hour and had no idea what the professor is teaching. Just for 9:52 watching a video and I completely understand. What a waste of paying tuitions!
@4g0ny
@4g0ny 10 жыл бұрын
i am in a c++ class where the teacher is of little to no use and this is delivered in exactly the way i need for my brain to digest it. a massive thanks to you, and a subscription as well.
@ahmadshah751
@ahmadshah751 2 жыл бұрын
other youtuber: "don't forget to like, comment & Subscribe" bucky: "don't forget to add your header file"
@ThatGuyNamedBender
@ThatGuyNamedBender 13 жыл бұрын
i love how no matter how short/long the tutorials are from bucky I always end up spending hours watching them [=
@BloodOrangeLover93
@BloodOrangeLover93 11 жыл бұрын
Dude you just helped me pass my programming exam, this question is always at the end of the paper
@MikoPellas
@MikoPellas 3 жыл бұрын
This video gave me that "ohhhhhhh" moment of understanding lol
@kenosentity6455
@kenosentity6455 4 жыл бұрын
You've been helping me since I was 13 bro.
@stucknsolve4875
@stucknsolve4875 3 жыл бұрын
10 years old video, but best explanation
@jackschluchter5707
@jackschluchter5707 4 жыл бұрын
This man is a better teacher than any professor ive had
@andeslam7370
@andeslam7370 5 жыл бұрын
awesome video, much shorter and sweeter than those taught during lectures.
@lukaskocman7546
@lukaskocman7546 3 жыл бұрын
Even after 10 years, it helped me a lot
@mohammad_bilal951
@mohammad_bilal951 5 жыл бұрын
opss man this video is 9 years old OMG and you are the best teacher online i ever had thank you very much SIR :)
@grossio5564
@grossio5564 5 жыл бұрын
very MUSH WTH AND OPSS WHAT KIND OF PERSON ARE YOU
@parcepabs1991
@parcepabs1991 2 жыл бұрын
I’ve watch like 8 9 videos and in 2 minutes you made a much more simpler code and did exactly what I was looking for
@godwinmandi8761
@godwinmandi8761 6 жыл бұрын
Print (" You Nailed It Dude, I Like The Seeding Part")
@TonyTxT
@TonyTxT 4 жыл бұрын
what the hell..!! he isn't teaching python
@hetaeramancer
@hetaeramancer 3 жыл бұрын
@@TonyTxT haha
@Foolyfish
@Foolyfish 12 жыл бұрын
THANK YOU, I really needed to know the srand function :P helped out a lot :D
@Allyg3000
@Allyg3000 11 жыл бұрын
In order to see the seconds from 1970 or whatever just type: cout
@tranqilo6453
@tranqilo6453 4 жыл бұрын
This lead me down a rabbit hole of computer history, thanks
@jaidev2717
@jaidev2717 5 жыл бұрын
A million second is just 12 days, Bucky.
@adamalrefai5838
@adamalrefai5838 5 жыл бұрын
pretty damn smart huh! -_-
@angelhernandezvega6064
@angelhernandezvega6064 4 жыл бұрын
We're living in 2020 while Bucky be living in 1970
@ddaniel.v
@ddaniel.v 3 жыл бұрын
im livin 12 days past 1970 too!
@Zovioh
@Zovioh 12 жыл бұрын
Bucky, you are officially who I'm learning my programming from now. The book I got is horrible and your channel separates the topics much better, so I can easily find what I need for my program.
@kpippink
@kpippink 10 жыл бұрын
Thanks for all wonderful videos Bucky. I am struggling to learn C++ for my programming class, but your videos help me a lot :D
@SeifOrabi
@SeifOrabi 11 жыл бұрын
Really enjoyed this tutorial Bucky. I've always had this problem in a simulation I was working on. But at least we know why now. As always, great tutorial!
@RedsBoneStuff
@RedsBoneStuff 9 жыл бұрын
Did you know there is computer hardware that allows you to make truly random number generators? It gives you a random value that you use as a seed. It's based on things that are scientifically random (or at least we do not understand them well enough to predict them). Various quantum phenomena are an option here. Quantum mechanics include so much randomness :P
@LeoMadrid
@LeoMadrid 9 жыл бұрын
+RedsBoneStuff Are you referring to a Psyleron REG?
@RedsBoneStuff
@RedsBoneStuff 9 жыл бұрын
Leo Madrid Not sure what they actually are :P
@vexion15
@vexion15 12 жыл бұрын
This was SOOOO helpful!!! :D I was getting ready to ask a question, but then you went and answered it before the video was over!
@TakingItCasual
@TakingItCasual 13 жыл бұрын
I want to scream my love for his tutorials but that'd make me look like some sort of fan boy, finishing his tutorials just fills me with... bliss.
@Adraria8
@Adraria8 9 жыл бұрын
The algorithm for random number generation is pretty simple actually. It basically involves multiplying really large numbers and taking their modulus on another really large number and using that as the next seed. Look up the linear congruential algorithm. You're vids r really helpful by the way!
@fifaham
@fifaham 3 жыл бұрын
@6:31 you may use the time function then use seconds and mints and probably date, mix them together or multiply them or whatever, so to make it look like more random
@ben1996123
@ben1996123 13 жыл бұрын
if anyone is struggling with rand(), and getting the correct range of numbers, use this: x+(rand()%(y-(x-1))) gives a random number from x to y inclusive, eg: 5+(rand()%(10-(5-1))) generates a number 5, 6, 7, 8, 9 or 10.
@onelerv1
@onelerv1 13 жыл бұрын
This is by far the best explaination of rand() I've ever seen, seriously bucky very very well done man.
@m4t4m0r0s
@m4t4m0r0s 3 жыл бұрын
Best video I’ve ever seen about this topic
@nextblain
@nextblain 13 жыл бұрын
FUN FACT: if u generate random numbers between 1 and 365, about only 30 of em, its almost sure that u will find 2 numbers same! (its called birthday problem from probability) awesome tut bucky! :)
@meloon2879
@meloon2879 8 жыл бұрын
you are the best! Keep doing these videos plzzzzzzzzzzzzzz!!!!!!!! love the way you teach and your humour is the best!
@kevinramdass8608
@kevinramdass8608 6 жыл бұрын
Thank you so much bucky youre a lifesaver...I appreciate your work so much
@tunamay0168
@tunamay0168 3 жыл бұрын
Thank you so much for saving a CS major student life
@ammarshah2366
@ammarshah2366 2 жыл бұрын
Yes, I can confirm that rand() doesn't truly generates random numbers. When I first called out rand(), it printed the same 41 as yours. Btw, thanks Bucky.
@realmrjangoon
@realmrjangoon 5 жыл бұрын
This guy is so good, I can watch the video at 2x speed, save time and understand the whwole thing
@hypermeero4782
@hypermeero4782 4 жыл бұрын
THANK YOUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU ur explanation was direct into the point simple LEGENDARY
@amygonzales8343
@amygonzales8343 5 жыл бұрын
Ugh I finally understand how "seed" works. Bucky kicks ass!
@helloworld12321
@helloworld12321 3 жыл бұрын
It's 2021 you r the best❤from Bangladesh
@tony2351992
@tony2351992 7 жыл бұрын
you are randomly amazing. love your videos man keep it UP
@xbz24
@xbz24 2 жыл бұрын
Bucky u are truly a god love you fella, SIMPLE ENOUGH
@yousefgamal4557
@yousefgamal4557 3 жыл бұрын
Your video was amazing, keep up the good work. I appreciate that, man.
@arnold9448
@arnold9448 8 жыл бұрын
You're amazing in teaching! Love it!
@loading_wait
@loading_wait 10 жыл бұрын
the algorithm does not change every second. it changes at every call of srand(...)
@Rigardoful
@Rigardoful 13 жыл бұрын
If I am not mistaken , rand() is actually a recursive function. It uses the result it last generated, to generate the next. So wha t srand() actually does, is make it not take the last result, but the number provided by it, or maybe one generated after a few calculations from the number you gave in srand(). That's what I was told at my university at least, I'm in my first year in ECE department, so I am not the most reliable source :D
@valizeth4073
@valizeth4073 4 жыл бұрын
1. Avoid "using namespace std" 2. Avoid "rand", use the contents from instead.
@kfdjhnhurjnnbjhu3ip410
@kfdjhnhurjnnbjhu3ip410 3 жыл бұрын
no
@Rawoonah2cool
@Rawoonah2cool 7 жыл бұрын
thanks dude,short and sweet tutorial
@Futureblur
@Futureblur 4 жыл бұрын
Just as sweet as your profile pic :D
@hamedalwafi8717
@hamedalwafi8717 7 жыл бұрын
I hope everyone appreciates these tutorals cause bucky u are fucking awesome ❤️❤️❤️❤️🔥🔥🔥
@KFilmsProduction
@KFilmsProduction 11 жыл бұрын
Random numbers in C++ have an algorithm, like (previous random number *((x*y + z)%n * m - k)/t ...) something like that, so the result is the same for it's first run on a computer, because it's using an algorithm, which uses constants and depends on value generated before. The probability of getting any number is almost equal, so the algorithm is considered as a random number generator. We need to change something, that bucky says :)
@NeilRoy
@NeilRoy 10 жыл бұрын
One handy feature of srand() is you can have the user provide a number for something like a level generator for a game (this is how many level generators work, where you can provide a number and it generates the same level, minecraft does this for example). You're just providing your own seed value. This can be handy, just so you know that you don't always want to use time(). Also, random number generators are not all t hat complex. I have written my own, and the reason why I wrote my own was so that if I ported my game to another computer system (different compilers use different algorithms for rand()) I had the same code for generating random numbers on all systems and so I get the same results. You may want to have the same seed so you get the same "random" set of numbers each time for a level generator, OR, you may have a game where you want the enemies to act the same way each time it is run so the player can get used to what happens in what order and they can learn to get past certain levels, so there is a certain amount of predictability. Here is the world's smallest random number generator (there are much more complex generators out that t hat produce much better, more unpredictable results, just google it). This works nicely, try it out... *unsigned long rng_seed;* *unsigned long rng(void) {* * return ((rng_seed = (rng_seed+1)*314159265L) >> 16) & 0xFFFF;* *}* Just set *rng_seed* to whatever seed value you wish (like time() or a fixed value), and then call *rng()*, using it the same way you would *rand()*.
@farhatmohammadi7224
@farhatmohammadi7224 8 жыл бұрын
I love you Bucky !
@moharjana
@moharjana 8 жыл бұрын
Sir You are cool and awesome :)
@samirgunic
@samirgunic 9 жыл бұрын
You would need a super accurate clock and a super fast computer to predict the seed before the computer that's generating the supposedly "random" number generates that number. You would also need the source code for the program and the function definition. It's not totally impossible, but it's not something most of us would ever want or need to do anyway. So pseudo-random numbers are good enough for most of us, and for most applications. Only a quantum computer would be able to generate truly random numbers, which is one of the reason they are hyped as the definitive solution for encryption.
@RealCoDeR
@RealCoDeR 3 жыл бұрын
Very good video . Waiting for Python programming ⌛
@lorenzorosales2916
@lorenzorosales2916 4 жыл бұрын
Thanks!!!!!! You explanation is clear and very helpful.
@asafel
@asafel 11 жыл бұрын
love your videos!!! thank a alot!
@Gervisj
@Gervisj 13 жыл бұрын
Thanks Bucky. I love the way you explain everything. You're awesome dude!
@radnyx_games
@radnyx_games 12 жыл бұрын
Yes but you would probably be using a different random, which is using different number modifications. Random isn't static, so time will only effect the random number you are generating at that time. (I'm not quite sure, but time is either updated every second or millisecond, if it's ms, then we don't have to worry, otherwise... goodluck?)
@isaacsarte2708
@isaacsarte2708 4 жыл бұрын
how about generating random numbers without repetition using array? in c++
@georgerotariu3221
@georgerotariu3221 4 жыл бұрын
Really helpful and well made. Keep it up!
@OmgitsLiz
@OmgitsLiz 4 жыл бұрын
cout
@dikukhanikar2837
@dikukhanikar2837 4 жыл бұрын
Wow... your explanation is sooo good
@Qazqi
@Qazqi 11 жыл бұрын
If you don't call srand(), the seed is 1 by default. Therefore, every conforming implementation will give everyone the same sequence until they change the seed.
@321DiagnoZa
@321DiagnoZa 5 жыл бұрын
great tutorial, I am curious to know how can I find the greatest and smallest number after the ocmputer randomly generates the numbers?
@ilbutti6796
@ilbutti6796 2 жыл бұрын
put results in a vector, than make a function that keeps in argument that vector as const reference, than make that function with a temp value, than, starting with a for loop from vector[0] until vector[vector.size()-1] if vector[i] > tmp { tmp = vector[i] } and make it return after the whole vector has been checked (the same but with < for the smaller. (if you know that your random numbers can't be, e.g. like in this video, > 6 or < 1, you could also optimizd your function by making it return directly when it finds a 1 or a 6)
@blind_neighbourhoodNerd
@blind_neighbourhoodNerd 5 жыл бұрын
excellent video man Thanks so much
@GertSmith-w3s
@GertSmith-w3s Жыл бұрын
Please help. Just a quick question. How did the compiler / program know that; I wanted the srand(VALUE), that was influenced by time, to be used in our 1+(rand()%6) equation? We never told it. Did we? :) BEST TUTORIAL ON THE NET. THANKS SOOOO MUCH
@TheCareertalk
@TheCareertalk 11 жыл бұрын
The numbers aren't really random. They just seem that way because the computer uses a complicated process to generate a number that seems random to humans. You need to "seed" the random number first. Bucky talks about this in the video.
@muhammadhariskhan8204
@muhammadhariskhan8204 5 жыл бұрын
Best Programming Teacher
@sydneyricafort4761
@sydneyricafort4761 6 жыл бұрын
i really love your videos bucky thanks a lot
@HappyDancerInPink
@HappyDancerInPink 10 жыл бұрын
Could you put the rand function into the srand parameter to get an even more complex random number generator?
@jaredcubilla7770
@jaredcubilla7770 10 жыл бұрын
cout
@SuperYtc1
@SuperYtc1 4 жыл бұрын
Nope because srand(rand()); would be the same as srand(41); The seed would be the time every time, so the random number list would be the same.
@hassansardar6649
@hassansardar6649 5 жыл бұрын
Love you sir Briliant explaination Cleared me well Thank you soo much ..
@RyansRecording
@RyansRecording 4 жыл бұрын
you explained it very well
@johnsoto7112
@johnsoto7112 4 жыл бұрын
why is the program only printing 21 numbers when you made the for loop 1
@lydiasteinberg5291
@lydiasteinberg5291 8 жыл бұрын
I'm at 6:50 in the video and having trouble with my code. I've done it exactly as he has (except for the srand, since if I can't get this much to work, I don't want to keep going until I can), but it keeps giving me these two error messages: "error: expected primary-expression before '(' token", and "error: expected primary-expression before '
@lydiasteinberg5291
@lydiasteinberg5291 8 жыл бұрын
***** Thank you so much! I didn't notice that's what I was doing there, it's really hard to see in the codeblocks font. I can't believe I got stumped on that. Thanks again for the help!
@togmeister8604
@togmeister8604 9 жыл бұрын
Bucky, wouldn't that be procedural then if your using a seed? Because when you do rand() it prints same number but when you do a seed it prints same number every time you use that seed. So shouldn't this tutorial be called Random and Procedural Number Generators. When you use the seed it's a predefined value hence it's procedural.
@qzer1990
@qzer1990 12 жыл бұрын
Most enlightening tutorial in a while, thanks man. But what functions do i.e. slot machines use? Probably not a simple rand() I guess. (;
@danielodette6013
@danielodette6013 6 жыл бұрын
Fun fact. When I tried rand() the first time, my random number was also 41.
@valizeth4073
@valizeth4073 4 жыл бұрын
Because rand is a garbage function and should definitely not be used.
@SuperYtc1
@SuperYtc1 4 жыл бұрын
@@valizeth4073 What do you think should?
@vend57
@vend57 6 жыл бұрын
random numbers are actually generated from the garbage values that are collected when a random variable is declared but not initialized. for instance, if you want to design a rand() function yourself, just follow this code : int main() { int a[100],i=0; while(i
@marcjooreja5903
@marcjooreja5903 8 жыл бұрын
WEheheyW!! thanx a lot man youre realy great!! I love u!!! hahaha!!! this is just what i needed!!!
@nathliea
@nathliea 8 жыл бұрын
I was trying to use this to generate a number between 1 and 100, so I put in %100 instead of %6, but every "random" result was divisible by 5. I am REALLY new to coding so I am sure I am doing something really wrong, but I did enjoy this tutorial even though I didn't understand most of it :)
@Darku.Matteru
@Darku.Matteru 9 жыл бұрын
very useful tutorial;) thx I needed that random generator rly bad..
@TheXRealXBrapp
@TheXRealXBrapp 13 жыл бұрын
And I used the loops variable to make it generate a new number EVERY time you use the function, rather than every second.
@tonyfalapatt1308
@tonyfalapatt1308 3 жыл бұрын
very nicely explained I don't what I can do for you but I liked and subbed and if I can I will watch more videos and like it 😀😁
@testingnames1995
@testingnames1995 7 жыл бұрын
How can we print the permutations of the elements in an array? for example the permutations of the numbers 1-2-3 are the following: 1-2-3, 1-3-2, 2-1-3, 2-3-1, 3-1-2, 3-2-1. How would we make a program that can find and PRINT the permutations of the values that the user has added to an array? I have been trying to do that for the last couple days but i haven't been able to succeed... At this point i was only able to print random values of the elements of an array acording to the size of it. I hope you can understand what i'm trying to say and what my problem is. Any help would be appreciated! Happy coding :)
@peri.platypus
@peri.platypus 2 жыл бұрын
Now I know, thanks for enlightening me
@farzambakht8354
@farzambakht8354 5 жыл бұрын
Good Teacher i really understannd very much
@SeekerofYab
@SeekerofYab 11 жыл бұрын
Thanks for the awesome videos. Also, would it be possible to make a completely random number generator by reading a analog to digital converter at a digit past its accuracy limit? Basically reading the noise?
@TheCareertalk
@TheCareertalk 11 жыл бұрын
The number that comes out of rand() is only pseudorandom, not truly random. It basically follows a little algorithm to create numbers. It looks random, but it's not quite.
@hdkimo
@hdkimo 6 жыл бұрын
i NEED help i want to generate a random array of 6 numbers ex: 6-5-31-42-27-10-15 and it has to be between 1 and 49 and i want to keep the same numbers while using the console. i dont want it to generate a new number every time i go back and forth in the menus that i created in the console but i want it to change every time i open a new console. thx
@six2gaming894
@six2gaming894 5 жыл бұрын
i under stand this but how to i get access to this number like setting it to an int or something
@pby1000
@pby1000 8 жыл бұрын
How is the value of srand(time(0)) being related to rand()? I hope this is clear. He does not use srand in the cout statement...
@TheK00paKingdom
@TheK00paKingdom 9 жыл бұрын
//Since everyone is posting their programs: #include #include #include using namespace std; int main() { cout
@ibiixie
@ibiixie 9 жыл бұрын
+TheKoopaKingdom I might as well do it too.... #include GLfloat light_diffuse[] = {1.0, 0.0, 0.0, 1.0}; /* Red diffuse light. */ GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0}; /* Infinite light location. */ GLfloat n[6][3] = { /* Normals for the 6 faces of a cube. */ {-1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}, {0.0, 0.0, -1.0} }; GLint faces[6][4] = { /* Vertex indices for the 6 faces of a cube. */ {0, 1, 2, 3}, {3, 2, 6, 7}, {7, 6, 5, 4}, {4, 5, 1, 0}, {5, 6, 2, 1}, {7, 4, 0, 3} }; GLfloat v[8][3]; /* Will be filled in with X,Y,Z vertexes. */ void drawBox(void) { int i; for (i = 0; i < 6; i++) { glBegin(GL_QUADS); glNormal3fv(&n[i][0]); glVertex3fv(&v[faces[i][0]][0]); glVertex3fv(&v[faces[i][1]][0]); glVertex3fv(&v[faces[i][2]][0]); glVertex3fv(&v[faces[i][3]][0]); glEnd(); } } void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); drawBox(); glutSwapBuffers(); } void init(void) { /* Setup cube vertex data. */ v[0][0] = v[1][0] = v[2][0] = v[3][0] = -1; v[4][0] = v[5][0] = v[6][0] = v[7][0] = 1; v[0][1] = v[1][1] = v[4][1] = v[5][1] = -1; v[2][1] = v[3][1] = v[6][1] = v[7][1] = 1; v[0][2] = v[3][2] = v[4][2] = v[7][2] = 1; v[1][2] = v[2][2] = v[5][2] = v[6][2] = -1; /* Enable a single OpenGL light. */ glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glEnable(GL_LIGHT0); glEnable(GL_LIGHTING); /* Use depth buffering for hidden surface elimination. */ glEnable(GL_DEPTH_TEST); /* Setup the view of the cube. */ glMatrixMode(GL_PROJECTION); gluPerspective( /* field of view in degree */ 40.0, /* aspect ratio */ 1.0, /* Z near */ 1.0, /* Z far */ 10.0); glMatrixMode(GL_MODELVIEW); gluLookAt(0.0, 0.0, 5.0, /* eye is at (0,0,5) */ 0.0, 0.0, 0.0, /* center is at (0,0,0) */ 0.0, 1.0, 0.); /* up is in positive Y direction */ /* Adjust cube position to be asthetic angle. */ glTranslatef(0.0, 0.0, -1.0); glRotatef(60, 1.0, 0.0, 0.0); glRotatef(-20, 0.0, 0.0, 1.0); } int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutCreateWindow("red 3D lighted cube"); glutDisplayFunc(display); init(); glutMainLoop(); return 0; /* ANSI C requires main to return int. */ }
@TheK00paKingdom
@TheK00paKingdom 9 жыл бұрын
It waits for the person to press any button.
@jammes327
@jammes327 8 жыл бұрын
+Josh Griffith Remove the question mark below after the closing curly brace. :)
@nitishprajapati8546
@nitishprajapati8546 8 жыл бұрын
+TheKoopaKingdom I think that ** cin.get(); ** is somewhat like ** system("pause"); ** which unfortunately now dosen't work in ANSI C++ compilers....[even clrscr(); dosen't ] However, cin.get(); too didn't work at one command. I needed to write it TWICE for it to work ONCE........ . . However, whats the algorithm or idea behind cin.get(); ....i know that cin is object of standard namespace......but get() ? How this command works.
@SansP3ur
@SansP3ur 6 жыл бұрын
Here's an alternative random seed generator that recasts the range from 0 to 4,294,967,295, rather than − 2,147,483,648 to 2,147,483,647: srand (static_cast (time(0)));
@SuperSebatube
@SuperSebatube 8 жыл бұрын
Hi, Bucky, congrats for this works. I hava a questions about the number 5, what is the case?. Greetings.
@saraesmayili
@saraesmayili 5 жыл бұрын
why everytime i use sand(number); before my for loop i got same numbers repeatedly in my result ?
@inx1819
@inx1819 5 жыл бұрын
Seed the RNG with time(0) like this srand(time(0))
@angelhernandezvega6064
@angelhernandezvega6064 4 жыл бұрын
you should have watched the whole video
True Random Numbers - Computerphile
12:16
Computerphile
Рет қаралды 130 М.
Сестра обхитрила!
00:17
Victoria Portfolio
Рет қаралды 958 М.
Леон киллер и Оля Полякова 😹
00:42
Канал Смеха
Рет қаралды 4,7 МЛН
The rand() Function (C++)
7:12
James Brodski
Рет қаралды 26 М.
Buckys C++ Programming Tutorials - 31 - Recursion
8:19
thenewboston
Рет қаралды 550 М.
why do header files even exist?
10:53
Low Level
Рет қаралды 440 М.
Forbidden C++
33:07
javidx9
Рет қаралды 1 МЛН
31 nooby C++ habits you need to ditch
16:18
mCoding
Рет қаралды 839 М.
Buckys C++ Programming Tutorials - 60 - class Templates
9:58
thenewboston
Рет қаралды 384 М.
How C++ took a turn for the worse
5:03
Code Persist
Рет қаралды 329 М.
Stack vs Heap Memory in C++
19:31
The Cherno
Рет қаралды 583 М.