Main Page | Directories | File List | Globals

fastrand.c

Go to the documentation of this file.
00001 /*
00002  * kernel_arch/i386/kernel/fastrand.c
00003  *
00004  * Copyright (c) 2003-2004 Lukasz Dembinski <dembol@nasa.com.pl>
00005  * All Rights Reserved
00006  * 
00007  * Date:        2004/01
00008  * Author:      Lukasz Dembinski
00009  * Info:        fastrand.c core file
00010  * Contact:     mailto: <dembol@nasa.com.pl>
00011  *
00012  */
00013 
00014 #include <agnix/agnix.h>
00015 
00016 #define RAND_CONST      33614
00017 
00018 unsigned int random_val = 1234;
00019 
00020 unsigned int _fastrand(u32 value)
00021 {
00022     unsigned int result;
00023 
00024     __asm__ ("mull %%ebx\n\t"
00025              "addl %%edx, %%eax"
00026     :"=a"(result)
00027     :"a"(value), "b"(RAND_CONST)
00028     );
00029     
00030     return result;
00031 }
00032 
00033 unsigned int fastrand(u32 range)
00034 {
00035     random_val = _fastrand(random_val);
00036     
00037     return random_val % range;
00038 }
00039 
Dokumentacje wygenerowano programem Doxygen 1.4.2 dla projektu Agnix