[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference noted::hackers_v1

Title:-={ H A C K E R S }=-
Notice:Write locked - see NOTED::HACKERS
Moderator:DIEHRD::MORRIS
Created:Thu Feb 20 1986
Last Modified:Mon Aug 03 1992
Last Successful Update:Fri Jun 06 1997
Number of topics:680
Total number of notes:5456

416.0. "-< Random Number Generator >-" by 38007::GUNDAVARAM (From the lab of the Mad Scientist!) Tue Mar 03 1987 00:33

	Hello:


	Does anybody have a random number generator written in DCL.

	I thought, I saw one in either this or the  DCL notesfile,

	but I can't find it. When I found it before, it wasn't much

	use for me, but I need it badly.



						Thanks,

						-- Shishir --
T.RTitleUserPersonal
Name
DateLines
416.1Image passing value via Symbol?MONSTR::DUTKONestor Dutko, VMS/VAXclusters CSSETue Mar 03 1987 01:212
    How about an image which generates a random number and then assignes
    it to a DCL Symbol which is accessible?  Would that do?
416.2CHOVAX::YOUNGBack from the Shadows Again,Tue Mar 03 1987 03:346
    This is pretty easy to do, takes about 5-10 minutes to whip up a
    simple one.  If you would describe your requirements here, I am
    sure that someone will rise to the challenge and supply you with
    one in short order.
    
    --  Barry
416.3-< Tried! >-38007::GUNDAVARAMFrom the lab of the Mad Scientist!Tue Mar 03 1987 10:3027
	Hello:

	
	I tried doing that in BASIC, and it didn't work, Can

	somebody do this in any other language or can anybody 

	give me something written in DCL. This is how it should be:


	$ Randomize (1,100)	! Randomize(Min,Max)

	Should produce a random number from 1 to 100.

	Then you should be able to print it, offcourse.

	$ Write Sys$Output Randomize


						Thanks,

				
						-- Shishir --

	


416.4Next week, we'll do it in tecoMAY20::MINOWI need a vacationTue Mar 03 1987 12:2117
$	seed = 1234567			! Initial seed -- any value ok
$	i = 0
$ loop:	gosub rand			! Calculate a random number
$	result_mod_100 = result / 100
$	result_mod_100 = result - (result_mod_100 * 100)
$	write sys$output "''result', ''result_mod_100'"
$	i = 1 + 1
$	if (i .lt. 10) then goto loop
$	exit 1
$!
$! Based on VMS mth$random (circa 1980) and Decus C rand()
$! This algorithm is prone to non-random sequences when considering
$! the next pseudo-random number.
$!
$ rand:	seed = (seed * 69069) + 1
$	result = seed .and. %x7FFFFFFF	! Make it positive
$	return
416.5This should work in BASICFROST::HARRIMANbicker,bicker,bickerTue Mar 03 1987 13:4819
1	external integer function lib$set_symbol(string by desc,	&
    						 string by desc,	&
    						 long by ref)
    	map (dclsym) string symbol_value = 3%
    
    	declare string constant symbol_name = "THE_RANDOM_NUMBER"
    
    	randomize
    
        a_random_number = rnd		! between 0 and 1
    					! mult by 100 and truncate
    
    	lset symbol_value = PLACE$((a_random_number * 100%),10000%)
    
    	ret% = lib$set_symbol(symbol_name,symbol_value,2%)
    
    	end
    
    	
416.6Oops.FROST::HARRIMANbrouhaha..balderdash..ballyhooTue Mar 03 1987 13:528
    Oops, the PLACE$ statement should read:
    
    LSET symbol_value = PLACE$(NUM1$(a_random_number * 100%),10000%)
    
    Teach me to type stuff in without trying it.
    
    /pjh
    
416.7F$CVT()BIRMIC::BELLMartin BellTue Mar 03 1987 14:487
    A quick way for a "sort of" random number is get the hundreths of
    a second out of F$TIME(). Ok if you aren't wanting the numbers very
    frequently, and they don't have to be reproducable.
    
    hows about F$CVTIME("","","HUNDREDTH") ????
    
    mb
416.8Thanks37966::GUNDAVARAMFrom the lab of the Mad Scientist!Tue Mar 03 1987 19:2615
	Hello:

	MAY20::MINOW - Mr. Minow's DCL procedure is very good , except

	that it keeps generating the same numbers every time you run it.

	Is there a solution for that ??



	P.S	Thanks for all the replies

						Regards & Thanks,
		
						-=- Shishir -=-
416.9Randomize on run timeCADSYS::SLATERKen SlaterTue Mar 03 1987 19:5115
    The way to get different results each time you run the procedure is to
    randomize the seed

$	seed = 1234567			! Initial seed -- any value ok

    The typical way to do this is to pickup the low order part of the
    system time and use it set the value of the seed, on the assumption
    that in terms of milliseconds, the time you start the program
    running is random. You might try:
    
$	seed = f$integer( f$extract( 18, 5, F$time() ) - "." )

    which pulls out the seconds and hundreths of seconds of the current
    time and treats it as a 4 digit decimal integer...Ken