Added: 2 years ago
From: thenewboston
Views: 58,423
Sort by time | Sort by thread (beta)

Link to this comment:

Share to:
see all

All Comments (176)

Sign In or Sign Up now to post a comment!
  • weird :/ it generated same numbers as your computer LOL :D

  • ok to all this who the numbers are always the same do this

    enter to your code

    <include<time.h#

    (and after the int (in this video its after int i = 1

    just do :

    ;((srand(time(NULL

    happy to help :)

  • Comment removed

  • Comment removed

  • Comment removed

  • Everyone is getting 41? I got 41 too...

  • variable % 10; variable modulus 10. NOT DIVIDE.

    you need to seed the random number generator or you will get repeat results.

  • The rand() function shall always return a number between 0 and RAND_MAX on the system. To find this "RAND_MAX" number, you simply do:

    printf("My rand() max is %d\n", RAND_MAX);

    And it should print it out. For instance, mine is 2,147,483,647, which coincidentally is the largest possible integer too. For Windows, however, it is only 32767, which is quite a shame.

  • I'm running the c file through the terminal in Fedora16, but it prints out the same numbers everytime I execute it...

  • @mjelma31 OK you explain it in the next video.Sorry I overreacted :P THNX

  • ITS NOT RANDOM! :( help

  • @sheshuke The rand function is not "actually" random.

  • It got errors saying"`rand' undeclared (first use this function) "

  • @sheshuke help!

    

  • @sheshuke same here

  • @sheshuke hey I found the solution, include the header stdlib.h in your program.

  • I got 2 billion XD

  • excellent tutorial ty for the hard work.

  • i dont why but i get an error at rand function in c,im using devc++ bloodshed

    (rand undeclared,first use of this function)

  • @demyrik pound include time.h try that

  • Comment removed

  • for those of you who havn't figured it out yet he tells you how to get a truely random number in the next tutorial c:

  • thank you ^_^ this helped me a lot

  • It's not random... mine is same as his... weird

  • wtf why are my numbers same as buckys ?? wtf nott rand shit ?

  • THUMBS UP IF YOU ALWAYS GOT THE SAME NUMBERS AS BUCKY!

  • not so random, my numbers were exactly the same as buckys :P

    

  • Is there any differene between stdlib.h and stdio.h? Should I include both in my code?

  • @PH5221 stdlib supports different functions for example malloc-dynamic memory allocation, if you are just starting out in C stdlib is not really needed stdio will do fine

  • ERM the random number is no so random, i got the exact same result as bucky did xD did anyone else get that? :D

  • @firefart3r I got 41 as well >.< i think something went wrong xDDD

  • @TheMedic1231 hehee xD he explains in next vid ^_^

  • @TheMedic1231 actually that is not a random functiona at all. cos i got exactly the same 20 numbers in the same order. heheh

  • @freetalk08 same. but its close enough, if you tweaked it enopugh, it could be random...

  • the reason why the program gives you 0 result is that you are using the math function module "%", the mathematical symbol for division is "/"

    -.^^

  • the reason why you have the same random number result is that the location of your data type is the same.. try using "FLOAT", if result will remains the same. try restarting your computer for its regenerate random location on your system.

    -opinion from a 1st year student ^^

  • the reason why it does randomize number from 0-32,000+ because the values inside the data type "INT" is equal to 0-32,727 i guess. the maximum number doesn't depends on your system but it depends on the data type your are using. ^^ correct me if I'm wrong

  • yeah i agree... me too .. its not random i think... i also get same exact number..

  • Not very random, I get the exact same numbers as you...

  • wooooooow i get massive numbers, ubuntu is awesome ;D

  • fail, random number are all the same for me :c

  • @cookiesRgood26 I mean it generates the same sequence of numbers every time, not that all the numbers are exactly the same.

  • @cookiesRgood26 same for me, i 'am getting the same numbers as you are. lol

  • Never mind I just moved onto the next tutorial and you explain why at the beginning of that one.

  • I don't get how this is a random function. You get 41, I get 41, re run it 20 more times I get 41. I continue with this tutorial and do the while loop, I get the exact same numbers as you no matter how many times I re-compile.

  • Comment removed

  • ‪I have problem with this tutorial. After typing the codes in the tutorial, my program didn't compile. I gives error messages.

  • @sydneyozful

    did u find iut how. if so let me know

  • Comment removed

  • Comment removed

  • retardet!!!!

    Use C#

  • weird how random isn't really random.

  • @djfoo000 you have to youse srand function ... they will not be same :)

  • 41 for me too.Not very random after all...

  • @utuber8781 most programming languages use seeds for random numbers for consistency of random functions

  • I got exactly the same 15 numbers also in that specific order. Kinda scary :p

  • I get 41 every time....

  • @guyzyl1 make sure your seeding it right

  • why return0 ; dont work?

  • OMG MY RANDOM NUMBER WAS 41 ALSO!!!!!! AAAAAAAAAAA!!! :)

  • #include 

  • This not not completely random yet... you'll get the same numbers that he does.

    If you want it to be truly random so u get different numbers every time, you gotta use srand() or the time() function.

  • Just found out that you have to include stdlib.h to use the ran() function.

  • @EVOX16

    it depends on the compiler you have. I dont need the stdlib.h to use rand() function.

  • @PivotBeguiner

    Ah, I was using XCode. Makes sense.

  • I sign up in youtube just to say thank you to you.. ^_^

    "thank YOU!" >_<

  • I get 41 every single time! lol

  • @TheRatiniked same here :D

  • Learn what 'srand' does and re-do this video.

  • It gives me the EXACT same numbers every time! I have it set to give me three random numbers (1 - 10) and it gives me 2, 8, then 5 in that order! Please help me out!

  • good example. thanks!

  • This doesn't really work as an dice since it gives the same numbers.

  • why do i get the same numbers as you?

    thanks.

  • yo bucky

    can you please explain this "%10" thing again? i dont really understand this...it devides the random number but why it always is the number that "smooth" then? like when i pick 5/10 or so it wouldnt work or what?

  • @eklok5000 ups got it, sorry

  • hey!what happen with this site??wtf!

  • why do i i get the exact same numbers every time?

  • omg i got 41 tooo :O

  • "oook, what I do, forgot a semi colon. That's embarrassing" LOL

  • Great tutorial :) keep doing :)

  • In Numerical Recipes in C: The Art of Scientific Computing (William H. Press, Brian P. Flannery, Saul A. Teukolsky, William T. Vetterling; New York: Cambridge University Press, 1992 (2nd ed., p. 277)), the following comments are made: "If you want to generate a random integer between 1 and 10, you should always do it by using high-order bits, as in j=1+(int) (10.0*rand()/(RAND_MAX+1.0)); and never by anything resembling j=1+(rand() % 10); (which uses lower-order bits)."
  • The versions of rand() and srand() in the Linux C Library

    use the same random number generator as random() and sran­

    dom(), so the lower-order bits should be as random as the

    higher-order bits. However, on older rand() implementa­

    tions, the lower-order bits are much less random than the

    higher-order bits.

  • It's always 41!!!! random my ass xD

  • Is that Dev - C++?

  • @vjromeguy ya, it is. he says he has it in his first tutorial i think

  • I got the same numbers as you got, so if many computer get the same random numbers I think we can crack the code for the slot machines at the casino :)

  • Your name is greg... im a genius

  • it say rand is undeclared. :/

  • when i choose only rand() and it gives always 41!

    How do i fix it?

  • @R4TH4CK3R Before you make your first call to rand(), seed the random number generator using the srand function.

  • Comment removed

  • @R4TH4CK3R go watch the next video, he explains it there.

  • The numbers aren't random. I'd get the same results every time I compiled and ran, and I got the same results as Bucky, too.

  • I got the same exact results as you, Bucky...

  • @crazynoob11 Ohhh, just watched the 13th vid. K nvm.

  • Function rand should have a prototype error. ~_~

  • What a nice idea to teach us how to get random numbers on the screen. :-)

    Your tutorials are my favourite tutorials on YouTube as well as HTML and XHTML-tutorials by an other chap.

    Anywawy, the point is, your C Programming Tutorial-Series is very good,and I've actually learned C from your tutorials. Nice work.

  • BORING! The numbers are the same

  • Great Tut.

  • Thx for this tutorial. Please how can i use a "for statement" to generate EVEN number between 1 and 10? Many thx

  • @Mcbere do a random number between 1 and 5, then multiply by 2?

  • @Rallybus Genius.

  • Comment removed

  • why is it always 41 is the first random number you get here..?? thats why when divided by 10., u got the remainder 1., and when by 6 and added 1 u got 6..??

  • @sidd9980 its the 'seed'.

    a random number generated from a seed to create a number depending on what the seed is.

    If you had a seen based on RTC(real time clock) and wanted random numbers between 0 and ten everytime u press the space bar, if u pressed it 1 time per second it would have 0,1,2,3,4,5,6,7,8,9,10,0,1,2,3­,4,5,6,7,89,10 ect.

    in this case, the seed is based on the code or number of lines (i think)

  • this is mildly interesting, the numbers that came up on my system are the same as yours.

  • @jackkniphe I got 41 as well. Odd.

  • for those who are having a problem with an undeclared rand function just add #include <stdlib.h> so that the rand function can be recognized. thanks bucky ive learned this from you on lesson 1 :)

  • @sOulrOckmelO Thanks!  It worked! I had that problem and this fixed it.

  • @sOulrOckmelO thankyou so much i

  • @sOulrOckmelO thankyou so much

  • @sOulrOckmelO i didnt See Stdlib.h in the leSSon one :O tell me i need to learn EVEREYH TING :D

  • hey neuboSton hao can i make a program vith a neat interface inStead of the cmd ? can u plz make tut or can anyone tell me plz i tink i need viSual baSic?? or Something? i need a vid LOL

  • after i compile it wont work can you help?

  • I can't see any differences between my code and yours, and I'm using Dev-C++ but when I go to compile and run this code it gives me the message, " 'rand' undeclared " and so it doesn't work.

  • i love you man. im currently taking logic and design.. and this is perfectly making sense. i feel genius.

  • I get very large numbers from the random function, 64-bit gcc on fedora 12

  • What .whatever did you save it as? My text editing program, textwrangler, uses that to decide what to run it as, because it handles pythons and phps and everything, so I have to know the .ending......

  • Comment removed

  • not random

  • @XDretsamtovip

    You need to add a function: srand(time(NULL));

  • cold i do this to get random characters

  • yes you could but i'm not sure how to do it. characters do have number values in the computer. maybe that's a tip.

  • @Digadogup yes.

    int variable = 67;

    printf("%c", variable);

    or typecast it

    char(variable)

    or

    (char)variable

  • It does the same thing every time :-/

  • @khjuiproductions you haven't seen next tutorial, have you'

  • @khjuiproductions thnx bro!

  • @khjuiproductions thnx bro! dude did you know all the list of #include so i can just put it all every i make a script .. if you know all .. give it to me .. thanks you ^^

  • can some give all the #include!? so, i just put it all every i make a script ,,

  • @monguiller what do you mean?

  • @khjuiproductions Watch the next video :)

  • @khjuiproductions

    See next tutorial! Bucky know that problem and he explain it in next tutorial.

  • To create a random number, just watch the next video instead of spamming this vid's comments!

  • These are not proper random numbers. I get the exact same numbers as you and the exact same numbers each time it's run. Proper random numbers should be different each time.

  • You cannot truly get random numbers from a computer. The best way to get random numbers is radio static from the atmosphere.

  • Same here. That's so weird.

  • omg i love you!!!!!

  • not exactly a function for choosing lotto numbers, if you want a different number each time...

  • Easiest random number generator: return 4;

  • my random number was 41 too

  • I am having an error ...it says that rand its undeclared plz help

  • How did you declare the random number?

  • Please, you don't have any idea what you're doing. Just look at your code formatting.

    Quote : "you can do a bunch of different math operators". Yeah...

  • Why if I have it print only one random number, it always gives me the same number?

  • the random function isn't exactly "random". The function is exactly what it says, a "function". Which means that its going to go on a specific path of operations. Just something to keep in mind.

    PS when you do this code he has up here, your going to get the EXACT SAME numbers as him :D

  • after watching 3 times i was able to understand it

  • did this not work for anyone? mine had an error saying

    9 C:\Programming\Random number functions.cpp `rand' undeclared (first use this function)

    can anyone give me a hand? i have exactly the same as bucky on my screen

  • Yeah. I am also having the same problem with Dev C++. It says 'rand' undeclared firs use ... error. How did you correct this?

  • When doing this in Dev-C++ I always get the same "random numbers", could someone please explain why?

  • Thank you.

  • ZZzz

  • uhh... i ran the program and i got the same results as you

  • i should message you my homework and you should code it for me,lol

  • "the fence post problem"

  • Max num is likely 65,535.

  • Thats an incorrect description of what the function does. It doesn't provide a random number, but a pseudo-random number. Remember that functions are just code, that perform instructions. Nothing random about that.. just a complex algorithm.

  • Yawn.

  • /agree

  • this is weird but i got it

  • well, i'd say the odds of getting caught in a group of 60 people is 1 in 60...

  • can i use it to find out what the odds of my getting caught at a party with 60 people there

  • i can t find your firts tutorial about c

  • for some reason after i put the rand part in it wont compile help please

  • Can I please see your compiler error, Tyleriscool45?

  • message me ur code and ill fix it for ya

  • just sent it check your messages

  • @thenewboston I did exact the same and compiler gave me 41 ;0

  • Hey dude what happened to the site this is your moderator P0w3r0f1.

  • dumb spammers kept postin and i got in trouble cuz they were posting adult content and i had adsense on my site

  • @thenewboston how do we contact u plz tell

Loading...
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more