в

Kazan Dev Alliance

Казанское Сообщество Разработчиков Программного Обеспечения

Официальный пример к функции rand()

Last post 04-01-2007 21:18 by Raimon. 0 replies.
Page 1 of 1 (1 items)
Sort Posts: Previous Next
  • 04-01-2007 21:18

    • Raimon
    • Top 10 Contributor
      Male
    • Joined on 08-18-2006
    • Kazan
    • Points 2,181

    Официальный пример к функции rand()

    что должна выдавать эта программа?

    пример из MSDN к функции rand():

    [code language="C#"]
    // crt_rand.c
    // This program seeds the random-number generator
    // with the time, then displays 10 random integers.
    //

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

    int main( void )
    {
    int i;

    // Seed the random-number generator with current time so that
    // the numbers will be different every time we run.
    //
    srand( (unsigned)time( NULL ) );

    // Display 10 numbers.
    for( i = 0; i < 10;i++ )
    printf( " %6d\n", rand() );

    printf("\n");

    // Usually, you will want to generate a number in a specific range,
    // such as 0 to 100, like this:
    {
    int RANGE_MIN = 0;
    int RANGE_MAX = 100;
    for (i = 0; i < 10; i++ )
    {
    int rand100 = (((double) rand() /
    (double) RAND_MAX) * RANGE_MAX + RANGE_MIN);
    printf( " %6d\n", rand100);
    }
    }
    }
    [/code]

    а что будет если, например, RANGE_MIN==10 ? :)
    Rail Sabirov
    Microsoft Certified Application Developer
    Microsoft Student Partner
    Теги: , ,
    • Post Points: 5
Page 1 of 1 (1 items)

© 2007 Kazan Developers Community and Post`s Authors