Заполнение генератора случайных чисел C ++ [дубликат]

This question already has an answer here:

How to generate a random number in C++? 10 answers

I have two questions.

What other ways are there to seed a psuedo-random number generator in C++ without using srand(time(NULL))?

The reason I asked the first question. I'm currently using time as my seed for my generator, but the number that the generator returns is always the same. I'm pretty sure the reason is because the variable that stores time is being truncated to some degree. (I have a warning message saying, "Implicit conversion loses integer precision: 'time_t' (aka 'long') to 'unsigned int') I'm guessing that this is telling me that in essence my seed will not change until next year occurs. For my purposes, using time as my seed would work just fine, but I don't know how to get rid of this warning.

I have never gotten that error message before, so I assume it has something to do with my Mac. It's 64-bit OS X v10.8. I'm also using Xcode to write and compile, but I had no problems on other computers with Xcode.

Редактировать: Изучив и изучив этот вопрос, я обнаружил ошибку, которая есть у 64-битных компьютеров Mac. (Пожалуйста, исправьте меня, если я ошибаюсь.) Если вы попытаетесь, чтобы ваш Mac выбрал случайное число от 1 до 7, используяtime(NULL) как семя, вы всегда получите номер четыре. Всегда. Я в конечном итоге с помощьюmach_absolute_time() посеять мой рандомизатор. Очевидно, это исключает всю переносимость из моей программы ... но я просто увлекаюсь.

Edit2: Исходный код:

#include <iostream>
#include <time.h>

using namespace std;

int main(int argc, const char * argv[]) {

srand(time(NULL));

cout << rand() % 7 + 1;

return 0;
}

Я снова запустил этот код, чтобы проверить его. Теперь он только возвращает 3. Это должно быть связано с моим компьютером, а не с самим C ++.

Ответы на вопрос(4)

Ваш ответ на вопрос