Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 random integers...help me please!
Index -> Programming, C++ -> C++ Help
Goto page Previous  1, 2, 3  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
rizzix




PostPosted: Thu May 05, 2005 8:18 pm   Post subject: (No subject)

its not really all that confusing.. cuz the language is basically the abstraction of the internal on/off, true/false circuit system of the hardware. of course there are layers and layers of this abstraction for various reasons.. and the lowest lever a "software developer" can access is the assembly language.

But... its not necessary to know all the little details.. but a good broad view of the subject is sometimes helpful..
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Thu May 05, 2005 8:44 pm   Post subject: (No subject)

jamonathin wrote:
wtd wrote:
They simply provide a way of turning C++ source code (the stuff humans can read) into machine code. Dev-C++ isn't even a compiler. Rather it's a program that simply uses the GCC compiler and advanced ways to edit and organize C++ source code.

Thats messed up. So why dont people ever learn the machine code, isn't it kinda like cheating then to use other programs? Because how do people write the programs such as Dev C++, by machine code?..... then who invented the machine code, and how did they write that?? it's all messed up to me Confused


Some people do know machine code.

A particular machine's internal "language" is devised by the people who create processors: IBM, Freescale, Intel, AMD, Via, etc.

But machine code is difficult to understand, so we have assembly language. It's much easier to understand, write, and maintain.

It's not good enough.

That's why we have high-level languages.

Also, if you write something in machine code directly, it'll run on exactly one kind of processor, and likely only one operating system. Write it in a high-level language and you can compile it on any system that has a compiler for that language.

Consider that, for instance, I can write:

code:
print_endline "hello world"


And compile it with:

code:
ocamlopt hello_world.ml -o hw


On any of 9 platforms, and it'll go off without a hitch and print "hello world".

This is called abstraction. It's telling the computer what you want it to do, rather than how to do it.
jamonathin




PostPosted: Fri May 06, 2005 1:23 pm   Post subject: (No subject)

Interesting . . .

wtd, what do you do for a living, because you seem know something about everything, you crazy |-|@X0|2
wtd




PostPosted: Fri May 06, 2005 3:40 pm   Post subject: (No subject)

I don't. I'm currently awaiting permission to work in Canada.

On a freelance basis I do web development from time to time. My goal in life is to be a professional student. Smile
jamonathin




PostPosted: Fri May 06, 2005 8:52 pm   Post subject: (No subject)

Are you an american, or some kinda terrorist? If you're goal in life is to be a professional student, my goal is to be your professional teacher. Razz
jamonathin




PostPosted: Tue May 10, 2005 12:21 pm   Post subject: (No subject)

Ok, I'm trying to do a program using random int's but I don't really understand the concept of it. I thought i did earlier, but then I tried it and i was like, wtf mayte?? Is there an easy way of just doing
Turing:

randint (number, 1, 10)
%or
number := Rand.Int (1, 10)

<blonde moment>
Andy




PostPosted: Tue May 10, 2005 6:35 pm   Post subject: (No subject)

why not actually read the help we've posted in the page before?
jamonathin




PostPosted: Tue May 10, 2005 8:57 pm   Post subject: (No subject)

I tried one of the programs you made, and I tried playing around with one of em, and I cant get anything out of it. And what I got from the original code you made always gave me a number greater than the second number, never a number inbetween. This is what I have so far.
c++:
//generate a random number between a specific range
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
   int m,n;
   cin>>m>>n;
  // srand((unsigned)time(NULL));
   cout<<(rand() % (m,n));
   int wait;
   cin >> wait;
   return 0;
}

But it still doesn't work.
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Tue May 10, 2005 9:02 pm   Post subject: (No subject)

What are you trying to do with:

code:
cout << (rand() % (m, n));


Oh, and please use space. It makes code more readable.
jamonathin




PostPosted: Wed May 11, 2005 5:35 am   Post subject: (No subject)

Sorry, i juss copied and pasted. lol. All i wanted to do is find a random int between m and n, and i was trying to figure out how to do that using the program that finds a random int between a specific range. That program didn't work right and so thats why I was playing with it. I tried lookin it up on the net too, but im havin a brain fart from hell Blowing up
md




PostPosted: Wed May 11, 2005 7:07 am   Post subject: (No subject)

Andy wrote:
...
if u want a sepcific range from n to m to then find out how many numbers there are in the range by taking (rand() % (m-n+1))+n

c++:

//generate a random number between a specific range
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
   int m,n;
   cin>>m>>n;
   srand((unsigned)time(NULL));
   cout<<(rand() % (m-n+1))+n;
   return 0;
}


It looks like you copied this, but didn't quite get it right... I'm sure if you look closely you'll see the problem.
jamonathin




PostPosted: Wed May 11, 2005 7:54 am   Post subject: (No subject)

Ah, i think I got it. drrrrr, lol. Yeah just that whole (m-n+1) thinger I didn't really understand, cuz I thought it ment more than it does, which is the max amount the rand can produce. Thanks for your help/patience Bday

c++:
//generate a random number between a specific range
#include <iostream>
using namespace std;
int main()
{
   int m,n;
   cin >> m >> n;
   cout << (rand() % (n))+ m;
   int wait;
   cin >> wait;
   return 0;
}


EDIT: nvm, it pulls up the same number every time, and if you restrict it to that number, it pulls up a different number every time.
wtd




PostPosted: Wed May 11, 2005 10:13 am   Post subject: (No subject)

jamonathin wrote:
EDIT: nvm, it pulls up the same number every time, and if you restrict it to that number, it pulls up a different number every time.


Because you're no longer seeding it with the time.
jamonathin




PostPosted: Thu May 12, 2005 8:36 am   Post subject: (No subject)

In conclusion I Hate Random Numbers Hit Wall . I got it to finally work (i had bran flakes this morning) so, sorry for the annoyance I caused you, but I thank you guys for puttin up with it Smile
betaflye




PostPosted: Wed Jun 08, 2005 6:13 pm   Post subject: (No subject)

jamonathin wrote:

Thats messed up. So why dont people ever learn the machine code, isn't it kinda like cheating then to use other programs? Because how do people write the programs such as Dev C++, by machine code?..... then who invented the machine code, and how did they write that?? it's all messed up to me Confused


Lots of people learn machine code, machine code is worth learning, it should be meantioned it isn't portable among processors or even operating systems. Dev C++ is written in Delphi, afaik.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 3  [ 33 Posts ]
Goto page Previous  1, 2, 3  Next
Jump to:   


Style:  
Search: