comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » random integers between 0 and 1,000,000
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
random integers between 0 and 1,000,000 [message #45972] Sat, 22 October 2005 19:29 Go to next message
mxd1007 is currently offline  mxd1007
Messages: 3
Registered: October 2005
Junior Member
Hello,
I'm trying to generate 30 random integer numbers between 0 and
1,000,000 but I keep getting negative values. This is my IDL
statements:

FOR i = 0, 29 DO BEGIN


weights[i] = ULONG(1000000 * RANDOMU( seed, 1 ))

ENDFOR



the result when I print out the array weights:

17925 28066 15706 -4558 7450 9892 5340 -1674 -29667
-15997
-27046 -27854 -24859 29529 -31310 -7807 21139 8014 -14189
-24471
-16476 -6624 -23456 3042 30319 -20737 10945 -19432 3206
-11725

I would think if you cast ULONG onto the calculation, you would get
postitive values.
thanks in advance.

-Mike
Re: random integers between 0 and 1,000,000 [message #46038 is a reply to message #45972] Tue, 25 October 2005 02:17 Go to previous message
Norbert Hahn is currently offline  Norbert Hahn
Messages: 46
Registered: May 2003
Member
"James Kuyper" <kuyper@wizard.net> wrote:

> Norbert Hahn wrote:
>> "James Kuyper" <kuyper@wizard.net> wrote:
>>
>>> takes a 32 bit unsigned long with a value somewhere in the range from 0
>>> to 1000000, and converts it into a 16 bit signed int, with a range from
>>> -32768 to 32767.
>>
>> I took a closer look on what might have gone on. I ran the following
>> program:
>>
>> z = randomu(seed,30)
>> a = long (z*1000000) & print, a
>> b = ulong (z*1000000) & print, b
>> i = fix(a)
>> print, a
>>
>> I found that a(1) was negative (-20848). So I printed

Sorry for the typo! The line should read
"I found that i(1) was negative (-20848). So I printed"
--------------|

The hex numbers given in my example were correct with leading zeroes
omitted.

Norbert
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: coordinates in threedimensional object graphics ?
Next Topic: another Dumb Widget question...

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 16:00:33 PDT 2025

Total time taken to generate the page: 0.00764 seconds