Thread: problem with random integer

  1. #1
    techno logic
    Guest

    problem with random integer

    hello,

    i want to make a random number between 1, and 10 that is different every time i use it. i want the integer to be called "my_number". here's what i have so far:

    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>

    int main ()
    {
    int seed = (int)time(NULL);
    srand(seed);
    rand();

    int my_number = 1+(int) (10.0*rand() / (RAND_MAX+1.0));


    could you tell me what is wrong??? thanks so much!!!

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Here is the short code for generating an integer from 1 and 10. I have a better algorithm, but I do not have the source code for it right now because I do not have access to my workstation.

    // Generate an integer between 1 and 10.
    int OneTen = 1 + rand() % 10;

    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  2. Random Number Range Problem.
    By xamlit in forum C Programming
    Replies: 11
    Last Post: 01-26-2006, 12:55 PM
  3. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  4. problem with random numbers
    By xxwerdxx in forum C Programming
    Replies: 2
    Last Post: 11-24-2005, 08:56 AM
  5. Help with homework please
    By vleonte in forum C Programming
    Replies: 20
    Last Post: 10-13-2003, 11:16 AM