HOME IRC
gelignite
Promotion
Nutzloses Wissen
Deine IP:
3.238.90.95

Dein Host:
ec2-3-238-90-95.compute-1.amazonaws.com

Seitenaufbau dauerte:


Aktuelle Uhrzeit (UTC):
05-10-2022 18:56:04

Letzten Lottozahlen [?]:
1, 3, 19, 37, 43, 49
SZ: 0
Tipps und Tricks
zurück

Pseudo random numbers between -1 and 1 (Pseudocode)


Direct link:
Tips und Tricks #9
Bezug:
General programming techniques

Details:
To generate (pseudo) random numbers in range of -1 and 1 you can do the following:

In case your rand() function returns numbers between MININT / MAXINT / MINDOUBLE / MAXDOUBLE or whatever:
cos( rand() ); // The cosine will return a number in range of -1 and 1.


In case your rand() function returns values between 0.0 and 1.0:
r = rand();
if( rand() % 2 == 0 ) // Switch sign randomly
r = -r;



Note:
It's not a real big problem that the cosine is deterministic due to the fact that random isn't really perfect, too. Hence this is pseudo random number generation.
Letzte Meldungen
13.08.2011 - Counter-Strike GO ...[more]

10.04.2011 - Monday Night Combat ...[more]

25.02.2011 - Humorvolles ...[more]

23.01.2011 - 1.5 GHz, 3 GB Speicher, ... ...[more]

20.01.2011 - Liste der QuakeNet Achievements und wie man sie bekommt bereitgestellt ...[more]

31.12.2010 - Guten Rutsch ...[more]

16.12.2010 - gelignAIte - Official Release ...[more]

11.11.2010 - openTTD AI ...[more]

26.10.2010 - Zeitreisen scheinen möglich ...[more]

04.09.2010 - Abschaltung "index.php4" ...[more]

Umfrage
Lieber ATI oder NVidia?

Legal notes
© 2000 - 2021 The Black Eagle Eyes, Alle Rechte vorbehalten