ראשי > תיכנות > שאלה בקשר לרנדומליות
יש מבין?
עריכה:
אגב, סתם נתתי פה דוגמאות של פעולות חשבון..[ההודעה נערכה על-ידי cp77fk4r ב-18/11/2004 16:34:00]
והוא אמר שיש איזה נוסחא ממש מסובכת לזה
אבל אני חושב שהיא באמת לוקחת נתונים מהשעון
אומשו כזה.
אני ישאל אותו ויביא לפה תנוסחא מתישו =]
אם לא- אז היא מבוססת על נשורת ראדיוהקטיבית.
(שמעתי שזה הדבר הראנדומאלי היחידי בעולם...- זאת אומרת ש_בינתיים_ בני האדם לא מצאו דרכים לחזות את זה {גם לא ל"שניה אחרי"})
The randomness formula you’re talking about is not complex, you can refer:
http://www.greatsnakes.com/Sepal/d4/d5/stdlib_8h.html#a26
( refer the rand and rand_r functions )
Second,
Cryptography usually have higher standards for PRNGs (Pseudo Random Number Generator ) sources and not an algorithm (like the ISO C one).
A nice alternative is the entropy pool:
In Unix, the kernel collects amounts of "randomness" from various devices (like mouse, keyboard, network, disk I/O activity, etc) to generate a fresh stream of random characters... all into one gigantic pool !
(usually /dev/random and /dev/urandom)
Various applications uses the entropy pool:
- crypto libraries and aps - openssl, openssh
- bind, nfs, apache
- etc etc etc....
clock activity is a poor choice for randomness due to the fact that its... predictable :)
I won’t refer windows operating system, because this system doesnt really exist, its a fiction of your imagination.
#include <stdlib.h> // ’rand’ , ’srand’ , ’printf’
#include <time.h> // ’time’ , ’time_t’
#include <iostream.h> // ’cout etc..’
#define lowest = 1; // define lowest possible value
#define highest = 6; // define highest possible value
int main()
{
time_t seconds; // declare variable to hold secondz on clock
time(&seconds); // get value from system clock and place in secondz variable
srand((unsigned int) seconds); // converts seconds variable to an unsigned int
int a = rand() % (highest - lowest + 1) + lowest; // get random value , set to variable a
cout << "Number: " << a; // print random number
system("PAUSE"); // Press any key to continue...
return 0; //Edit - forgot to explain about this - terminating the program.
}
[ההודעה נערכה על-ידי phax ב-13/12/2004 17:52:52]
ב#define השם חייב להיות באותיות גדולות!
the main idea was to understand the rnd and not lame errors in C++ like you mentioned.
זה לא מה שהוא ביקש...
מה שהוא רצה זה איך עוושים פונקציה שכזו
לא להשתמש בפונקציות פשוטות כמו srand ו - rand
הוא רצה לדעת איך מכינים אותם
סיפי, יש הבדל בין ראנדומאלי ללא צפוי!
ונשורת רדיואקטיבית, בתוך מחשב:)?
לא ניראה לי שאירגון התקנים הבין לאומי יאשר מחשב שמתרחשים בו ביקועים על ימין ועל שמאל:)
ושלא לדבר על האנרגייה והכסף שמושקע בביקוע גרעין, זה לא כזה פשוט..
וגם הזיהום של הסביבה.
נשורת גרעינית זה חומר מסוכן!..
קיצר זה מבוסס על ערך כלשהוא(יכול להיות מהשעון כמו שסיפי אמר)ומבצע על הערך הזה מספר פעולות מתמטיות.
ואל תדבר מחוסר ניסיון בבקשה.
קוד:
#include <stdio.h>
#include <windows.h>
//#include "small.h"
int main(int argc, char *argv[])
{
srand(GetTickCount());
system("color 2");
while(1)
{
printf("%d", rand()%9);
}
return 0;
}
זה מעין מייטריקס ג’נרייטור שכתבתי...סמאל.ה זה קובץ אופטימיזציה קטן ואין ליחס לו חשיבות
ליצור סידרת מספרים...
המספר הזה לרוב הוא השעון...
אבל יכול להיות מש שתרצו ואם פעמיים תיקחו אותו מספר לייצור סדרה..
תקבלו אותם מספרים "רנדומליים"