Wednesday, August 06, 2008

人体不同部位信号的警示

现代人营养不足并非缺吃少喝引起的,而是追求过分精制食品和不注意营养平衡造成的。

唇部信号:

唇部开裂、唇线模糊,是唇病的先兆,说明缺乏维生素B2及维生素C。

补充办法:多吃青菜、柑橘、西红柿、瓜果、马铃薯等。服维生素B和服维生素C片。

舌部信号:

如发现舌头过于平滑,味蕾凸
起发红,舌尖两侧发黄、发白,说明叶酸和铁质欠缺。缺乏这类物质,将导致骨髓内红血球的生产受到阻碍,从而引起舌炎、贫血、胃肠功能紊乱,生长发育不良。

补救办法:多吃肝脏、菠菜、黑面包并 补救办法:多吃肝脏、菠菜、黑面包并服用含有叶酸成分的B族维生素营养丸。

口部信号:

若发现口角发红、长期干裂而且口唇和舌头疼痛,你很可能是营养不足而患上口角炎,如不注意,就会引起口疮和淋巴结炎。口角炎的成因多为缺乏铁质和维生素B2(核黄素)及维生素B6造成。从人体内部说,缺乏这两种维生素会引起贫血,影响人体生长发育。

补救办法:吃菠菜等绿叶蔬菜,常食猪、牛肉、肝脏、豆类等。服维生素B族营养丸。

鼻子信号:

若鼻子两边发红,油腻光亮发红常脱皮,说明你体内缺锌。缺锌会引起食欲不振和新陈代谢障碍。

补充办法:大部分食品中都含有锌,只要不偏食,缺锌现象可以得到纠正。亦可服用含有锌的多种维生素营养丸。

头发信号:

头发拔出时无痛感、发丝易缠卷,说明缺乏维生素C和铁质,而头发色泽变浅、变淡,是维生素B12偏低的信号。缺乏维生素B12者体内红血球的生产和神经系统都会受到影响。

补救办法:多吃乳类食品、肝脏、鱼类和豆类。补充B族维生素。

指甲信号:

指甲上有白点,表示缺锌。指甲易断裂,是缺铁。

补救办法:多吃菠菜、肝脏和猪、牛、羊肉,服用含有锌的多种维生素。

Fancy meeting you

surprised to meet you.

Tuesday, August 05, 2008

Monday, August 04, 2008

Driving test passed

Congratulation to myself ... 12 error out of 15, not bad. Waiting for my drive license ...

Saturday, August 02, 2008

New pictures uploaded

To http://picasaweb.google.com/lanxin0106 . Welcome everyone to enjoy my journey of life ...

good article

说明:这首诗是今年四川的高考满分作文,今年四川以坚强为话题,写一篇文体不限的文章。该考生以歌行体和楚辞体写汶川地震,并且这是一首藏头诗,第一排下来分别是地震灾区的地名,可见其才华横溢! 戊子岁,四月初八。川静其波,鸟罢其鸣。一场无情的天灾袭来,举国恸哭。在灾难面前,我们选择坚强;在悲痛中,我们选择坚强 。汶川坚强,四川坚强,中国坚强!因为坚强,我们不怕灾难;因为坚强,我们明天更美好!
————
汶水东流不复西,神仙难改地震袭。
川蜀儿女多苦难,一片荒城尽眼底。
映现当年唐山景,尽是残垣与断壁。
秀丽河山浩劫后,昨日今朝各两异。
都道零八年岁好,为何灾难紧相逼。
江山如画景色美,怎奈苍天生妒忌。
北国刚受冰冻灾,天府又遭夷平地。
川静其波鸟罢鸣,齐哀满目皆疮痍。
江天五月渐阴沉,满腔悲痛灰色弥。
油绿麦田无人收,万千苍生宿路隅。
平生有泪不轻弹,今朝闻此泪如泥。
武候诸葛若有知,不堪目视亦掩泣。
彭祖寿延八百载,可知人命仅须臾。
州州郡郡华夏土,一砖一瓦似金玉。
金玉散去不足惜,金玉怎比万事
花儿凋谢来年开,来年风景更旖旎。
茂年男儿体健壮,安能袖手闻羌笛。
理会百姓疾与苦,血汗合流同舟济。
绵薄微力不足道,奇迹因爱八方聚。
竹丝管弦为君鸣,可敬可赞可歌泣。
卧薪含悲建家园,蜀山青青蜀水碧。
龙的传人谁可胜,只手亦有撑天力。
汉羌一家爱无疆,我齿你唇永相依。
旺兴岁月定轮回,红霞当空雄鸡啼。
红烛数盏列堂前,潜心默祈哀思寄。
白云苍狗命难料,生者奋进逝者息。
青史铭刻五一二,永记今朝万人罹。
川蜀儿女多坚强,还把灾难视蝼蚁。
立我于高山之上兮,眺望远方。惟见山河齐悲兮,黯然神伤。
立我于高山之上兮,眺望远方。还看万众一心兮,不屈脊梁。
立我于高山之上兮,展望悲中奋起兮。多难兴邦,中华坚强!

Tuesday, May 20, 2008

gcc参数详解

zz from: http://www.bloghome.cn/posts/10410

[版本] 0.13
[声明]
这篇文档是我的关于gcc参数的笔记,我很怀念dos年代我用小本子, 纪录所有的dos 命令的参数.哈哈,下面的东西可能也不是很全面,我参考了很多的书,和gcc的帮助.不全的原因是,有可能我还没有看到这个参数, 另一种原因是,我可能还不会用它 不过,我会慢慢的补齐的.哈哈 如果你要转在本文章请保留我email(pianopan@beeship.com)和文章的全面性.
[介绍]
gcc and g++分别是gnu的c & c++编译器 gcc/g++在执行编译工作的时候,总共需要4步
1.预处理,生成.i的文件[预处理器cpp]
2.将预处理后的文件不转换成汇编语言,生成文件.s[编译器egcs]
3.有汇编变为目标代码(机器代码)生成.o的文件[汇编器as]
4.连接目标代码,生成可执行程序[链接器ld]

[参数详解]
-x language filename
  设定文件所使用的语言,使后缀名无效,对以后的多个有效.也就是根据约定C语言的后缀名称是.c的,而C++的后缀名是.C或者.cpp,如果你很个性, 决定你的C代码文件的后缀名是.pig 哈哈,那你就要用这个参数,这个参数对他后面的文件名都起作用,除非到了下一个参数的使用。
  可以使用的参数吗有下面的这些
  `c'', `objective-c'', `c-header'', `c++'', `cpp-output'', `assembler'', and `assembler-with-cpp''.
  看到英文,应该可以理解的。
  例子用法:
  gcc -x c hello.pig
  
-x none filename
  关掉上一个选项,也就是让gcc根据文件名后缀,自动识别文件类型
  例子用法:
  gcc -x c hello.pig -x none hello2.c
  
-c
  只激活预处理,编译,和汇编,也就是他只把程序做成obj文件
  例子用法:
  gcc -c hello.c
  他将生成.o的obj文件

-S
  只激活预处理和编译,就是指把文件编译成为汇编代码。
  例子用法
  gcc -S hello.c
  他将生成.s的汇编代码,你可以用文本编辑器察看

-E
  只激活预处理,这个不生成文件,你需要把它重定向到一个输出文件里面.
  例子用法:
  gcc -E hello.c > pianoapan.txt
  gcc -E hello.c | more
  慢慢看吧,一个hello word 也要与处理成800行的代码

-o
  制定目标名称,缺省的时候,gcc 编译出来的文件是a.out,很难听,如果你和我有同感,改掉它,哈哈
  例子用法
  gcc -o hello.exe hello.c (哦,windows用习惯了)
  gcc -o hello.asm -S hello.c

-pipe
  使用管道代替编译中临时文件,在使用非gnu汇编工具的时候,可能有些问题
  gcc -pipe -o hello.exe hello.c

-ansi
  关闭gnu c中与ansi c不兼容的特性,激活ansi c的专有特性(包括禁止一些asm inline typeof关键字,以及UNIX,vax等预处理宏,

-fno-asm
  此选项实现ansi选项的功能的一部分,它禁止将asm,inline和typeof用作关键字。     
-fno-strict-prototype
  只对g++起作用,使用这个选项,g++将对不带参数的函数,都认为是没有显式的对参数的个数和类型说明,而不是没有参数.
  而gcc无论是否使用这个参数,都将对没有带参数的函数,认为城没有显式说明的类型
  
-fthis-is-varialble
  就是向传统c++看齐,可以使用this当一般变量使用.
  
-fcond-mismatch
  允许条件表达式的第二和第三参数类型不匹配,表达式的值将为void类型
  
-funsigned-char
-fno-signed-char
-fsigned-char
-fno-unsigned-char
  这四个参数是对char类型进行设置,决定将char类型设置成unsigned char(前两个参数)或者 signed char(后两个参数)
  
-include file
  包含某个代码,简单来说,就是便以某个文件,需要另一个文件的时候,就可以用它设定,功能就相当于在代码中使用#include
  例子用法:
  gcc hello.c -include /root/pianopan.h
  
-imacros file
  将file文件的宏,扩展到gcc/g++的输入文件,宏定义本身并不出现在输入文件中
  
-Dmacro
  相当于C语言中的#define macro
  
-Dmacro=defn
  相当于C语言中的#define macro=defn
  
-Umacro
  相当于C语言中的#undef macro

-undef
  取消对任何非标准宏的定义
  
-Idir
  在你是用#include"file"的时候,gcc/g++会先在当前目录查找你所制定的头文件,如果没有找到,他回到缺省的头文件目录找,如果使用-I制定了目录,他
  回先在你所制定的目录查找,然后再按常规的顺序去找.
  对于#include,gcc/g++会到-I制定的目录查找,查找不到,然后将到系统的缺省的头文件目录查找
  
-I-
  就是取消前一个参数的功能,所以一般在-Idir之后使用
  
-idirafter dir
  在-I的目录里面查找失败,讲到这个目录里面查找.
  
-iprefix prefix
-iwithprefix dir
  一般一起使用,当-I的目录查找失败,会到prefix+dir下查找
  
-nostdinc
  使编译器不再系统缺省的头文件目录里面找头文件,一般和-I联合使用,明确限定头文件的位置
  
-nostdin C++
  规定不在g++指定的标准路经中搜索,但仍在其他路径中搜索,.此选项在创libg++库使用
  
-C
  在预处理的时候,不删除注释信息,一般和-E使用,有时候分析程序,用这个很方便的
  
-M
  生成文件关联的信息。包含目标文件所依赖的所有源代码你可以用gcc -M hello.c来测试一下,很简单。
  
-MM
  和上面的那个一样,但是它将忽略由#include造成的依赖关系。
  
-MD
  和-M相同,但是输出将导入到.d的文件里面
  
-MMD
  和-MM相同,但是输出将导入到.d的文件里面
  
-Wa,option
  此选项传递option给汇编程序;如果option中间有逗号,就将option分成多个选项,然后传递给会汇编程序
  
-Wl.option
  此选项传递option给连接程序;如果option中间有逗号,就将option分成多个选项,然后传递给会连接程序.
  

-llibrary
  制定编译的时候使用的库
  例子用法
  gcc -lcurses hello.c
  使用ncurses库编译程序
  
-Ldir
  制定编译的时候,搜索库的路径。比如你自己的库,可以用它制定目录,不然
  编译器将只在标准库的目录找。这个dir就是目录的名称。
  
-O0
-O1
-O2
-O3
  编译器的优化选项的4个级别,-O0表示没有优化,-O1为缺省值,-O3优化级别最高     
-g
  只是编译器,在编译的时候,产生调试信息。
  
-gstabs
  此选项以stabs格式声称调试信息,但是不包括gdb调试信息.
  
-gstabs+
  此选项以stabs格式声称调试信息,并且包含仅供gdb使用的额外调试信息.
  
-ggdb
  此选项将尽可能的生成gdb的可以使用的调试信息.

-static
  此选项将禁止使用动态库,所以,编译出来的东西,一般都很大,也不需要什么
动态连接库,就可以运行.

-share
  此选项将尽量使用动态库,所以生成文件比较小,但是需要系统由动态库.

-traditional
  试图让编译器支持传统的C语言特性

[参考资料]
-Linux/UNIX高级编程
  中科红旗软件技术有限公司编著.清华大学出版社出版
-Gcc man page
  
[ChangeLog]
-2002-08-10
  ver 0.1 发布最初的文档
-2002-08-11
  ver 0.11 修改文档格式
-2002-08-12
  ver 0.12 加入了对静态库,动态库的参数
-2002-08-16
  ver 0.16 增加了gcc编译的4个阶段的命令

运行 gcc/egcs

**********运行 gcc/egcs***********************
  GCC 是 GNU 的 C 和 C++ 编译器。实际上, GCC 能够编译三种语言:C、C++ 和 Object C(C 语言的一种面向对象扩展)。利用 gcc 命令可同时编译并连接 C 和 C++ 源程序。
  如果你有两个或少数几个 C 源文件,也可以方便地利用 GCC 编译、连接并生成可执行文件。例如,假设你有两个源文件 main.c 和 factorial.c 两个源文件,现在要编译生成一个计算阶乘的程序。
代码:

-----------------------
清单 factorial.c
-----------------------
int factorial (int n)
{
  if (n <= 1)
   return 1;
  else
   return factorial (n - 1) * n;
}
-----------------------
清单 main.c
-----------------------
#include 
#include 

int factorial (int n);
int main (int argc, char **argv)
{
  int n;

  if (argc < 2)
  {
    printf ("Usage: %s nn", argv [0]);
    return -1;
  }
  else
  {
   n = atoi (argv[1]);
   printf ("Factorial of %d is %d.n", n, factorial (n));
   }
  return 0;
}


-----------------------
利用如下的命令可编译生成可执行文件,并执行程序:
$ gcc -o factorial main.c factorial.c
$ ./factorial 5
Factorial of 5 is 120.

   GCC 可同时用来编译 C 程序和 C++ 程序。一般来说,C 编译器通过源文件的后缀名来判断是 C 程序还是 C++ 程序。在 Linux 中,C 源文件的后缀名为 .c,而 C++ 源文件的后缀名为 .C 或 . cpp。但是,gcc 命令只能编译 C++ 源文件,而不能自动和 C+ + 程序使用的库连接。因此,通常使用 g++ 命令来完成 C++ 程序的编译和连接,该程序会自动调用 gcc 实现编译。假设我们有一个如下的 C ++ 源文件(hello.C):
#include
void main (void)
{
  cout << "Hello, world!" << endl;
}

则可以如下调用 g++ 命令编译、连接并生成可执行文件:
$ g++ -o hello hello.C
$ ./hello
Hello, world!


**********************gcc/egcs 的主要选项*********
gcc 命令的常用选项
选项 解释
-ansi 只支持 ANSI 标准的 C 语法。这一选项将禁止 GNU C 的某些特色,
例如 asm 或 typeof 关键词。
-c 只编译并生成目标文件。
-DMACRO 以字符串“1”定义 MACRO 宏。
-DMACRO=DEFN 以字符串“DEFN”定义 MACRO 宏。
-E 只运行 C 预编译器。
-g 生成调试信息。GNU 调试器可利用该信息。
-IDIRECTORY 指定额外的头文件搜索路径DIRECTORY。
-LDIRECTORY 指定额外的函数库搜索路径DIRECTORY。
-lLIBRARY 连接时搜索指定的函数库LIBRARY。
-m486 针对 486 进行代码优化。
-o FILE 生成指定的输出文件。用在生成可执行文件时。
-O0 不进行优化处理。
-O 或 -O1 优化生成代码。
-O2 进一步优化。
-O3 比 -O2 更进一步优化,包括 inline 函数。
-shared 生成共享目标文件。通常用在建立共享库时。
-static 禁止使用共享连接。
-UMACRO 取消对 MACRO 宏的定义。
-w 不生成任何警告信息。
-Wall 生成所有警告信息。

Friday, January 11, 2008

RAND、RANDOM_NUMBER(ZZ)

from http://140.136.191.181/html/frank/document/fortran/intrinsic_function/random_number.htm

RAND、RANDOM_NUMBER(取亂數)


※請注意,Fortran 90 有新語法

o2000 中,rand的說明文件,適用Fortran 77 與 90:
【請注意:ran 為 real 型態,rand 為 double 型態】
RAND(3F)                                                              RAND(3F)

NAME
rand, irand, srand - random number generator

SYNOPSIS
integer iseed, i, irand
double precision x, rand

call srand(iseed)

i = irand( )

x = rand( )

DESCRIPTION
Irand generates successive pseudo-random integers in the range from 0 to
2**15-1. rand generates pseudo-random numbers distributed in [0, 1.0].
Srand uses its integer argument to re-initialize the seed for successive
invocations of irand and rand.

SEE ALSO
rand(3C).

Page 1

RAN(3I)                                                Last changed: 1-6-98

NAME
_ranf, RANF, RANGET, RANSET - Computes pseudo-random numbers

SYNOPSIS
C/C++:

#include

double _ranf(void);

Fortran:

RANF()

RANGET ([I=]i)

RANSET ([K=]k)

Fortran on UNICOS/mk systems only:

RANSET ([K=]k [, [J=]j])

IMPLEMENTATION
C/C++: UNICOS and UNICOS/mk systems

Fortran: UNICOS, UNICOS/mk, and IRIX systems

STANDARDS
C/C++: Cray Research extension

Fortran: CF90 compiler extension to Fortran 90

DESCRIPTION
The _ranf and RAND functions return a pseudo-random floating-point
number in the range of 0.0 < x < 1.0.

The RANGET intrinsic procedure returns a seed from the random number
seed table.

The RANSET function establishes a seed in the random number seed
table.

C/C++ NOTES
Because _ranf is an intrinsic function, no externally visible library
function is available for it.

FORTRAN NOTES
RANF obtains the first or next in a series of pseudo-random numbers.
Parenthesis are required, that is: var = RANF(). If an argument is
supplied, it is ignored.

The RANGET intrinsic function obtains a seed. It can be called as a
function or a subroutine; it is recommended that this routine be used
as a function. RANGET has an optional integer argument. If present,
the argument is set to the seed. The argument for RANGET is as
follows:

i An integer of default kind (KIND=8). If present, RANGET returns
the seed in i.

On UNICOS and UNICOS/mk systems, the RANSET intrinsic function
establishes a seed by using the lower 48 bits of the argument. The
result type is typeless. If no argument or a zero argument is
supplied, the seed is reset to an initial default value. When the
seed of the random number generator is reset, RANSET does not store
the supplied argument as the first value in the buffer of the random
number seeds. If an argument is supplied, the lower 48 bits are used
as the random-number seed. The rightmost bit is always set to 1.

The RANSET arguments are as follows:

k An optional integer, real, or Boolean argument of default kind
(KIND=8) The range of argument k is |k| < inf, where inf is as
follows:
2450
* On UNICOS systems, infinity is approximately 10 .
308
* On UNICOS/mk and IRIX systems, infinity is approximately 10 .

j An optional integer argument that, if specified, is used as a
count for skipping the first section of sequential random
numbers. You can use this to create a complete sequence of
random numbers while running on many PEs by breaking up the
sequence into subsequences and using RANSET() to get each
subsequence started in the correct location.

The names of these intrinsics cannot be passed as arguments.

THE RANF ALGORITHM
In Fortran on CRAY C90 systems, the random number generation algorithm
uses the following two equations:

* S(n+1) = M1*S(n) mod 2**48

* S(n+64) = M64*S(n) mod 2**48

Each S(i) is the ith seed.

The first equation is used to generate the first 128 random numbers
and store them in a table if a call to RANSET() was done. Otherwise,
the table contains the first 128 random numbers from the default seed.
The second equation is used because it vectorizes.

The default seed is S(0) = 1274321477413155 (octal).

The operations M1*S(n) and M64*S(n) are done as integer
multiplications in such a way to preserve the lower 48 bits. It is
the lower 48 bits that make the next random number seed and are used
in the return value.

The return value (random number) is the newly generated seed with an
exponent of 40000 (octal) added. This is normalized before exit.

The multiplier M1 is 1207264271730565 (octal) and is related to M64 by
the following expression:
M64 = lower 48 bits of M1**64 = 7027423346125401 (octal).

For example, the following Fortran program, when compiled with the
f90 -i 64 option on a CRAY C90 system, is the equivalent of the RANF
function:

cc
c THIS IS A FORTRAN VERSION OF RANF() FUNCTION
cc
REAL FUNCTION RANF()
REAL NORM
INTEGER MHI,MLO,EXPO,SEED,SEEDHI,SEEDLO
DATA SEED/1274321477413155B/
SAVE SEED

MHI = 12072642B
MLO = 71730565B

EXPO = SHIFTL(40000B,48)

SEEDHI = SHIFTR(AND(SHIFTL(77777777B,24),SEED),24)
SEEDLO = AND(77777777B,SEED)

SEED = AND(7777777777777777B,SEEDLO*MLO+
1 SHIFTL(SEEDLO*MHI+SEEDHI*MLO,24))

RANF=NORM(OR(EXPO,SEED),0.0)
RETURN
END
cc
c THIS IS HERE TO NORMALIZE THE FLOATING POINT RESULT
cc
REAL FUNCTION NORM(X,Y)
REAL X,Y
NORM = X+Y
RETURN
END

On IRIX systems, RANF uses a 64-bit linear congruential generator with
a default seed of 1274321477413155 (octal).

THE RANF REPEAT PERIOD
In Fortran, the period of RANF() is 2**46. If you need to insure that
two random number ranges do not overlap, you can determine this
empirically by generating the two sets of numbers and comparing them
against one another, and also against themselves, for an overlap. It
should be noted, however, that when using RANSET to set the random
number seed, the algorithm used always rounds up even-numbered seeds
to the nearest odd-numbered seed (that is, the right most bit is
always set to one). Some adjacent pairs of seeds will generate
exactly the same set of random numbers. For example, seeds 4 and 5
will generate the same set of random numbers.

RANF AND MULTITASKING
In Fortran, the random number generator uses static memory storage for
the random number seed table, so the RANF, RANSET, and RANGET
functions must be protected (locked) when called from a multitasked
program.

RANF generates a set of random numbers such that each random number
depends on the previous random number for its value. Thus, depending
on the order in which the tasks calling RANF execute, a different set
of random numbers will be returned to each task. It cannot be
guaranteed that each task will get a distinct and reproducible set of
random number values.

RETURN VALUES
_ranf and RANF return a 64-bit floating-point number in the range
0.0 < x < 1.0.

RANGET returns a 64-bit integer result.

RANSET returns a 64-bit typeless result.

EXAMPLES
The following examples are written in Fortran:

DO 10 I=1,10
10 RANDOM(I)=RANF()

CALL RANGET(iseed1)
C or
iseed=RANGET(ivalue)

CALL RANSET(ivalue)
C or
dummy=RANSET(ivalue)

SEE ALSO
RANDOM_NUMBER(3I), RANDOM_SEED(3I)

rand(3C) in the UNICOS System Libraries Reference Manual, publication
SR-2080

A complete list of C/C++ intrinsic functions available on Cray
Research systems is in the Cray C/C++ Reference Manual, publication SR
-2179.

Intrinsic Procedures Reference Manual, publication SR-2138, for the
printed version of this man page.

提醒:

  1. 範例程式中,rand部分,變數 x , rand 型態需宣告為 double precision,否則會傳回 0.0。

  2. 若要使用real型態,請用 ran( )。

  3. iseed 若未提供或每次一樣,每次執行所得亂數相同,可利用如時間函數

    • o2000下使用 f77:secnds(1.)可傳回系統秒數

    • MS-Fortran:利用GETTIM(ihr,imin,isec,i100th)函數,傳回十、分、秒、百分之一秒


關鍵字:pseudorandom numbers(偽隨機數)

Fortran 90 透過 random_seed 做初始設定,並透過 random_number 傳回介於 0 到 1 的亂數值。

若需要的是介於 A 到 B 的亂數值,可利用 A+ (B-A) * RandomNumber

或 M + INT (K * RandomNumber) ,可得到 M 到 M+K-1 的隨機整數

o2000 中,random_number的說明文件,適用Fortran 90:
RANDOM_NUMBER(3I)                                      Last changed: 1-6-98

NAME
RANDOM_NUMBER - Returns pseudorandom numbers

SYNOPSIS
CALL RANDOM_NUMBER ([HARVEST=]harvest)

IMPLEMENTATION
UNICOS, UNICOS/mk, and IRIX systems

STANDARDS
Fortran 90

DESCRIPTION
The RANDOM_NUMBER intrinsic subroutine returns one pseudorandom number
or an array of pseudorandom numbers from the uniform distribution over
the range 0 <= x < 1. It accepts the following argument:

harvest Must be of type real. It is an output argument. It may be
a scalar or an array variable. It is set to contain
pseudorandom numbers from the uniform distribution in the
interval 0 <= x < 1.
harvest Must be of type real. It is an output argument. It may be
a scalar or an array variable. It is set to contain
pseudorandom numbers from the uniform distribution in the
interval 0 <= x < 1.

On UNICOS and UNICOS/mk systems, harvest is 64 bits. On
IRIX systems, harvest is 32 bits.

The name of this intrinsic cannot be passed as an argument.

EXAMPLES
REAL X, Y(10,10)
! Initialize X with a pseudorandom number
CALL RANDOM_NUMBER(HARVEST=X)
CALL RANDOM_NUMBER(Y)
! X and Y contain uniformly distributed random numbers

SEE ALSO
RANDOM_SEED(3I), RANF(3I)

Intrinsic Procedures Reference Manual, publication SR-2138, for the
printed version of this man page.

 

o2000 中,random_seed的說明文件,適用Fortran 90:
RANDOM_SEED(3I)                                        Last changed: 1-6-98

NAME
RANDOM_SEED - Restarts or queries the pseudorandom number generator

SYNOPSIS
CALL RANDOM_SEED ([[SIZE=]size] [,[PUT=]put] [,[GET=]get])

IMPLEMENTATION
UNICOS, UNICOS/mk, and IRIX systems

STANDARDS
Fortran 90

DESCRIPTION
The RANDOM_SEED intrinsic subroutine restarts or queries the
pseudorandom number generator used by RANDOM_NUMBER. It accepts the
following arguments (note that there must be exactly one argument or
no arguments present):

size Must be scalar and of type integer. It is an output argument.
It is set to the number N of integers that the processor uses
to hold the value of the seed.

put Must be an integer array of rank one and size >= N. It is an
input argument. It is used to set the seed value.

get Must be an integer array of rank one and size >= N. It is an
output argument. It is set to the current value of the seed.

The name of this intrinsic cannot be passed as an argument.

EXAMPLES
CALL RANDOM_SEED ! initization of seed
CALL RANDOM_SEED(SIZE = K) ! Sets K = N
CALL RANDOM_SEED(PUT = SEEDARRAY(1:K)) ! Set user seed
CALL RANDOM_SEED(GET = OLDSEED(1:K)) ! Get current seed

SEE ALSO
RANDOM_NUMBER(3I)

Intrinsic Procedures Reference Manual, publication SR-2138, for the
printed version of this man page.

 

o2000 中,ranf的說明文件:
RAN(3I)                                                Last changed: 1-6-98

NAME
_ranf, RANF, RANGET, RANSET - Computes pseudo-random numbers

SYNOPSIS
C/C++:

#include

double _ranf(void);

Fortran:

RANF()

RANGET ([I=]i)

RANSET ([K=]k)

Fortran on UNICOS/mk systems only:

RANSET ([K=]k [, [J=]j])
RAN(3I) Last changed: 1-6-98

NAME
_ranf, RANF, RANGET, RANSET - Computes pseudo-random numbers

SYNOPSIS
C/C++:

#include

double _ranf(void);

Fortran:

RANF()

RANGET ([I=]i)

RANSET ([K=]k)

Fortran on UNICOS/mk systems only:

RANSET ([K=]k [, [J=]j])
RAN(3I) Last changed: 1-6-98

NAME
_ranf, RANF, RANGET, RANSET - Computes pseudo-random numbers

SYNOPSIS
C/C++:

#include

double _ranf(void);

Fortran:

RANF()

RANGET ([I=]i)

RANSET ([K=]k)

Fortran on UNICOS/mk systems only:

RANSET ([K=]k [, [J=]j])
RAN(3I) Last changed: 1-6-98

NAME
_ranf, RANF, RANGET, RANSET - Computes pseudo-random numbers

SYNOPSIS
C/C++:

#include

double _ranf(void);

Fortran:

RANF()

RANGET ([I=]i)

RANSET ([K=]k)

Fortran on UNICOS/mk systems only:

RANSET ([K=]k [, [J=]j])

FORTRAN NOTES
RANF obtains the first or next in a series of pseudo-random numbers.
Parenthesis are required, that is: var = RANF(). If an argument is
supplied, it is ignored.

The RANGET intrinsic function obtains a seed. It can be called as a
function or a subroutine; it is recommended that this routine be used
as a function. RANGET has an optional integer argument. If present,
the argument is set to the seed. The argument for RANGET is as
follows:

i An integer of default kind (KIND=8). If present, RANGET returns
the seed in i.

On UNICOS and UNICOS/mk systems, the RANSET intrinsic function
establishes a seed by using the lower 48 bits of the argument. The
result type is typeless. If no argument or a zero argument is
supplied, the seed is reset to an initial default value. When the
seed of the random number generator is reset, RANSET does not store
the supplied argument as the first value in the buffer of the random
number seeds. If an argument is supplied, the lower 48 bits are used
as the random-number seed. The rightmost bit is always set to 1.

The RANSET arguments are as follows:

k An optional integer, real, or Boolean argument of default kind
(KIND=8) The range of argument k is |k| < inf, where inf is as
follows:
2450
* On UNICOS systems, infinity is approximately 10 .
308
* On UNICOS/mk and IRIX systems, infinity is approximately 10 .

j An optional integer argument that, if specified, is used as a
count for skipping the first section of sequential random
numbers. You can use this to create a complete sequence of
random numbers while running on many PEs by breaking up the
sequence into subsequences and using RANSET() to get each
subsequence started in the correct location.

The names of these intrinsics cannot be passed as arguments.

THE RANF ALGORITHM
In Fortran on CRAY C90 systems, the random number generation algorithm
uses the following two equations:

* S(n+1) = M1*S(n) mod 2**48

* S(n+64) = M64*S(n) mod 2**48

Each S(i) is the ith seed.

The first equation is used to generate the first 128 random numbers
and store them in a table if a call to RANSET() was done. Otherwise,
the table contains the first 128 random numbers from the default seed.
The second equation is used because it vectorizes.

The default seed is S(0) = 1274321477413155 (octal).

The operations M1*S(n) and M64*S(n) are done as integer
multiplications in such a way to preserve the lower 48 bits. It is
the lower 48 bits that make the next random number seed and are used
in the return value.

The return value (random number) is the newly generated seed with an
exponent of 40000 (octal) added. This is normalized before exit.

The multiplier M1 is 1207264271730565 (octal) and is related to M64 by
the following expression:
M64 = lower 48 bits of M1**64 = 7027423346125401 (octal).

For example, the following Fortran program, when compiled with the
f90 -i 64 option on a CRAY C90 system, is the equivalent of the RANF
function:

cc
c THIS IS A FORTRAN VERSION OF RANF() FUNCTION
cc
REAL FUNCTION RANF()
REAL NORM
INTEGER MHI,MLO,EXPO,SEED,SEEDHI,SEEDLO
DATA SEED/1274321477413155B/
SAVE SEED

MHI = 12072642B
MLO = 71730565B

EXPO = SHIFTL(40000B,48)

SEEDHI = SHIFTR(AND(SHIFTL(77777777B,24),SEED),24)
SEEDLO = AND(77777777B,SEED)

SEED = AND(7777777777777777B,SEEDLO*MLO+
1 SHIFTL(SEEDLO*MHI+SEEDHI*MLO,24))

RANF=NORM(OR(EXPO,SEED),0.0)
RETURN
END
cc
c THIS IS HERE TO NORMALIZE THE FLOATING POINT RESULT
cc
REAL FUNCTION NORM(X,Y)
REAL X,Y
NORM = X+Y
RETURN
END

On IRIX systems, RANF uses a 64-bit linear congruential generator with
a default seed of 1274321477413155 (octal).

THE RANF REPEAT PERIOD
In Fortran, the period of RANF() is 2**46. If you need to insure that
two random number ranges do not overlap, you can determine this
empirically by generating the two sets of numbers and comparing them
against one another, and also against themselves, for an overlap. It
should be noted, however, that when using RANSET to set the random
number seed, the algorithm used always rounds up even-numbered seeds
to the nearest odd-numbered seed (that is, the right most bit is
always set to one). Some adjacent pairs of seeds will generate
exactly the same set of random numbers. For example, seeds 4 and 5
will generate the same set of random numbers.

RANF AND MULTITASKING
In Fortran, the random number generator uses static memory storage for
the random number seed table, so the RANF, RANSET, and RANGET
functions must be protected (locked) when called from a multitasked
program.

RANF generates a set of random numbers such that each random number
depends on the previous random number for its value. Thus, depending
on the order in which the tasks calling RANF execute, a different set
of random numbers will be returned to each task. It cannot be
guaranteed that each task will get a distinct and reproducible set of
random number values.

RETURN VALUES
_ranf and RANF return a 64-bit floating-point number in the range
0.0 < x < 1.0.

RANGET returns a 64-bit integer result.

RANSET returns a 64-bit typeless result.

EXAMPLES
The following examples are written in Fortran:

DO 10 I=1,10
10 RANDOM(I)=RANF()

CALL RANGET(iseed1)
C or
iseed=RANGET(ivalue)

CALL RANSET(ivalue)
C or
dummy=RANSET(ivalue)

SEE ALSO
RANDOM_NUMBER(3I), RANDOM_SEED(3I)

rand(3C) in the UNICOS System Libraries Reference Manual, publication
SR-2080

A complete list of C/C++ intrinsic functions available on Cray
Research systems is in the Cray C/C++ Reference Manual, publication SR
-2179.

Intrinsic Procedures Reference Manual, publication SR-2138, for the
printed version of this man page.