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

Link to this comment:

Share to:
see all

All Comments (114)

Sign In or Sign Up now to post a comment!
  • can we make it a random case whileloop?

  • i love ur jumber numberator :)

  • @ttognala U can always try it, for me it doesn't work

  • Make more C tutorials please Bucky!

  • time identifier not found keeps coming up in my program, whats the story with that?

  • Bucky, thanks for the tutorials. They are very helpful. I've got a question. In this tut you showed us how to use srand. How do you limit the generated random numbers to a given interval (say, a number between 1 and 100)? In the previous tut, you taught us that the formula 1+rand()%100 would do the trick. But I tried to modify this tut to make the program generate a seed random number between 1 and 100, and I got the same number 15 times.

  • Jumber generator :D love your jokes and tutorials

  • 41 18467 6334 26500 19169 15724 11478 29358 26962 24464 5705 28145 23281 16827 9961 How strange. This is "random" numbers I get.
  • @ttognala no. the point is that an algorithm cannot produce truly random numbers. therefore inputting a number that is returned from an algorithm is going to give the same output.

  • For those who use Linux (GCC) use stdlib.h and time.h instead conio.h. Anyway, thank you Bucky ;)

  • but in linux there will be no conio.h

  • Awesome... srand along with time!

  • hallu guys ahm.. how am i going to arrange the random numbers from least to greatest?? would you help me/?

  • u r awesome

  • Implicit declaration of function time

  • WTF!?

    it was much easier and different when using BORLAND C

  • "NICE!"

  • is there any way to assign the random value to a variable? like if i wanted to get a random number, but then use the same random number later on.

  • Comment removed

  • @XcXtrippyXcX thanks bro, dunno why your comment got removed though :P

  • Hi there Bucky, and the rest of you!

    You have really good videos, and everything has gone good until now for me. "srand" works fine, but when I add the time parameter, it wont work!

    I included stdlib.h

    This is my output: srand(time(NULL));

    ........^

    %CC-I-IMPLICITFUNC, In this statement, the identifier "time" is implicitly decla

    red as a function.

    at line number 6 in file SYS$SYSDEVICE:[EGHURTIG.CC.CPT­1]PROGRAM.C;4

    I guess I should include some additional header, but I don't know which! :)

  • @ehurtig006 try including time.h

    

  • @bondservant4Him

    Yeah, thank you! Actually I already tried that and it worked great!

    I meant to reply to myself with this info, but I couldn't post anything more at the time.

    Nevertheless, thank you very much! :)

  • Of course, you could argue that there's no such thing as a random number full stop, as when a human picks one there are always factors influencing that decision. What does it expect me to choose? What haven't i chosen in a while?

  • hi how to generate random numbers with a range? hm lets say i wan the random numbers to be within a range of 20 - 30? thx. (:

  • @zaidento Watch the tutorial just before this one, and the answer to your question is "20+rand()%11" rather than "rand()"

  • @zaidento couldn't you just use the tip he used in the previous video? you use the % sign to calculate the remainder with 10 different values, and then add 20?

  • Thanks again!

  • I have a question: Why my program doesn't stop generating numbers. I actually used the same code up there. What is the solution>?

  • @jodzjcm pm me ur code ill look at it

  • @bondservant4Him :) Thanks for the concern :) I already fixed it. I copied the exact code up there. But I forgot to remove the scanf function from my previous project (Im using the same sheet from my previous).

  • @jodzjcm sounds like i doesn't reach the limit, is it definately incrementing on each loop?

  • have some fun whit the tutorial...:D

  • My "random" numbers are exactly the same...they are really random...:D

  • want a really random number generator try this for the srand function. srand(rand() * srand());

    and just use any operator you want.

  • @ssjmysticgohan I tried that and put time(NULL) inside both - got the same numbers everytime, any ideas why?

  • @DixonNxn not sure let me test that out again. i'm doing networking now so i lost some of what i was learning about C

  • i got 41 in the first number :O

  • I've tried both " srand(time(NULL)); " and " srand(time(0)); " (obviously without the " " ) -both seem to generate 0's and no actual numbers - I'm using xcode 3.2.6 - and I'm working in a standard main.c file... does anyone know why this would be generating a bunch of 0's? (fyi - I have it looped like 30 times, and it's all 0's fml)

  • @LukiPooki send me your code ill take a look at it

  • rofl, your brain did use some random pattern to generate words "jumber numberater"

  • Thanks! I'm subscrived. You convinced me! Great tutorials!

  • help pls, `time' undeclared (first use this function)

  • Sorry, my iPod seems to replace greater than and less than signs with hyphens

  • #include -time.h-

    (You forgot the last greater than sign)

  • Hi, nice video, for those who facing time() error, add #include <time.h

  • why do you keep using the while loop where the for loop shines?

  • srand(time(NULL)); doesn't work foe me

  • @TrancendedTora NULL is not defined in the C standard library. Use 0 (zero) instead, or after your includes add the line #define NULL 0 and it will work. Some C implementations will define it, but not all, so that may be why it works for the author and not for you.

  • the time(NULL) function didn't work so well with me ...why ??

  • Good trick! That was pretty random, but what happened to the first number? I would like to know. I suppose getting a totally random number is impossible after all. But good try! Thanks for the explanation and keep the good work!

  • @rapidopato The first numbers were different; on the first run it was 9930 and on the second run it was 9972. They may not be far off from one another, but still different, and moreover if you were to use the modulo operator to get a random number between 0 and 9, [rand() % 10] you would get 0 back in the first run and 2 back in the second run.

  • I researched wooping cough, and it is pretty bad... Best get that checked out.

  • visit technoexam website for more details on c programming !

    large program library, source codes, examples with output, header files, file handling, lecture notes, study notes, question papers, answers, quiz, objectives quesionts and many more !!!!!!!!!!!!!!

    ---- technoexam - online website

  • thanks!

  • Jummer generator? Jumper generator? Where are we jumping to Buck. LOL

  • Thank You. Thank You so much for uploading this. I can now finish my HW and have a lot of fun with it. You are a genius. I've already subscribed to learn some more from you. ^_^

  • @IsTI37Cluj

    nice game!

  • At 2:32 he's about to cough!

  • cant you do srand(A)

    A == 0

    and then a++

  • @god4506

    no, it just run one time at all , so the result are always same as the frist time

  • Haha no more wooping cough :P

  • I see....

  • That's not truly random number, it still follow pattern, you need to add more randomness to srand in order to get more truly random number

  • If u have problem because compiler says " `time' undeclared (first use this function) " well u have to add this # include <time.h> and if rand and srand doesnt work you have to add # include <stdlib.h> nice work Bucky keep it on!

  • @Thorgils1 why does he uses conio.h, is it necessary?

  • @manutube8080 hey conio.h is used to allow getch();

  • @Thorgils1 no its not. i erased my conio.h and worked fine.

  • this is a good explanation. I was reading about srand and didn't quite understand how the number was selection was called by the input of time. Visually helped me out here. Don't quite understand what the NULL purpose is. I have seen this done srand (time(0)) what is the difference?

  • i miss the line; "Sorry its my whopping cough".

  • @savezera rofl, although he says "whooping cough" which it definitely isn't as that's a pretty serious disease :-)

  • the problam that the random number just going up and not really random :(

  • Coment out the 'seed' can sometimes be helpful during testing so that fixed Random Numbers are produced for testing against.

    Great and Helpful Video's

  • That's very good tutorial!!

  • i am doing a dice game, i have created 5 panels, and i want to randomly generate a letter in each of those panels,

    static char *Symbols[]={"A","K","Q","J","P­","S"};

    either 1 of those letters.

    however when i click the roll button, the same letters keep coming up, and they dont change, i need it to keep on randomly displaying different letters.

  • Random things:

    FAN SPEED RPM

    CPU TEMP

  • its really helpful thanks :)

  • 10q so much for z explanatuion B.

  • lol so after 24 hours you'l get the same al last time

    sweet vid im noob so im going to surgest u do srand(rand())

  • @Digadogup if you do srand(rand()) it will give you the same numbers every time you run the program. the time() function gives you unix time which is different every second (for example unix time right now is 1267392718 in Toronto, Ontario)

  • it doesnt compile

  • this does not work, it keeps returning the same value all the time because you did it wrong. here is an easier way:

    int random(int max)

    { int seed = timeGetTime();  return (seed % max);

    }

    usage:

    int y = random(4); //generates number from 0-4

  • `srand' undeclared (first use this function)

    `time` undeclared (first use this function)

  • `srand' undeclared (first use this function) `time` undeclared (first use this function)

    I gues these errors when I compile and run, any help? DevC++ and VC++ both give the same error.

  • Ok I really need to look at the title of the next tutorial before making comments!

    Piece of trivia. I tried srand(srand()) which seemed to work quite well. LOL.

    BTW Why has 'return 0;' suddenly appeared? What's it for?

  • @icekat83 return 0 is used to tell the main function that your not returning anything to it (because he put main's return parameters as 'int') just put void main to avoid using return 0

  • Also, very useful videos (y)

  • Haha I love you're 'Wooping cough' and Jumber Numberator! :)

  • It keeps saying 8 `time' undeclared (first use this function)

  • Quanantum mechanics

  • jumber numberater

  • your a cool kid

  • I can understand you better when you say "As you can see" about the jumber numerator...

  • lol

  • In lecture one day, prof was talking about using random numbers that seed from the electricity gauged in a circuit to the computer. IDK, how that could be implemented, but that seems pretty damn random if you could get it to work!

  • Thanks a lot for this tutorial! :)

  • awesomee:)

  • what recording software are you using??

  • camtasia

  • @VampieGames dev ++

  • Sweeeet! Thanks Bucky!

  • Also, you could just make an applet, and handle a max number, then make a few classes to handle randomized paths.

  • Ehh, I'm not really a C fan.

    If you can tell by my Username, I'm more of a Java freak. But, if I'm correct, Java derived from C, so I should know the basics already. Except, I noticed you, could also do something like this.

    int rand()

    { random_seed = random_seed * 1103515245 +12345; return (unsigned int)(random_seed / 65536) % 32768;

    }

  • erm.. java is like c with oop, all in a sandbox.

  • ohhh i gettt it

    :)

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