• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

any c++ IDE recommendations for Mac? I'm not going to be writing any GUI/DX/production code, just some research bits and pieces. Something that automates building, gives me some basic refactoring tools, plays well with git, doesn't screw with the working directory too much and gives me some auto-complete functionality would be ideal.

Xcode seems like the obvious choice, but it might be overkill. I'm already very familiar with Eclipse and vim, but I feel like vim might be a little too lightweight (yes, I know what you're about to type, stop typing) for the project and last time I checked Eclipse's C++ plugins weren't spectacular.
No, Xcode's about right for OS X. It's tied to the hip with LLVM/Clang which is a very solid environment for modern C and C++ development, and it installs a complete distribution of Clang command line tools the first time you launch it. LLDB and Instruments are well integrated for debugger workflow.

Just create a new project, OS X Application -> Command-Line Tool and select C or C++ as your language of choice. You're good to go from there.

The University of Michigan has a pretty quick guide to the basics for C++ programming in Xcode, you need only follow it up to "Testing on CAEN".
 

KageZero

Member
If you're really interested in audio programming, I've been slowly making my way through the following book, which has been suggested by a few websites for the purpose of developing virtual musical instruments of the VST sort, for use in Cubase or Pro Tools.

The Audio Programming Book starts with a quick intro to C, just enough C++, and goes into several examples of real time audio programming with the Csound library. Half the almost 900 page book (no joke) is a crash course discussion of C/C++ programming fundamentals with occasional references to music theory, as they've tried to make this accessible to a wider audience.

I like the coverage of material, and I don't think it skips out on stuff. It does make me want to try a course that covers music composition and playing someday, maybe a Ukulele course is in my future?

That's probably the sanest way to dive in that I know of. Csound abstracts a fair number of audio recording and capture APIs that can be either messy to manage and very OS specific or too high level to do anything interesting with, and it offers some nice plugin interfaces to change waveforms in real time. It's cool stuff.

Give it a shot, take it easy, and don't get too intimidated. It's a fascinating subject on its own.

Okay will take a look into it, thanks
 

Giggzy

Member
This isn't a programming question, but given the OT, I assume there are quite a few CS grads in here. I'm hoping someone can help me out.

I'm going to be starting at my local university this fall for a degree in Computer Science, and I potentially have the opportunity to receive $5k a year of tuition reimbursement through my employer. However, I need to explain to them how my CS degree will be job-related and beneficial to the company. They normally only offer this to people getting a degree in Mechanical Engineering, Chemical Engineering, and business.

About the company I work: they are a leading provider of mission-critical manufacturing support services and contamination detection and protection products to the semiconductor, microelectronic, and solar industries.

Basically, we clean used engineering equipment. Any advice on what I can say to show how my degree is beneficial to the company? I hate asking for help on this, but I'm at a loss for what to say.

Thanks :)
 
Bit of a request.

I have never used Linux before. Ever.
I am taking an Operating Systems class that wants us to write a Hello, World program in Kernel Module. Writing in Bash was no problem. However, this kernel stuff is tough for a newcomer.

If anyone is available to help me, I can offer some type of compensation. I know, very simple for Linux guys- but tough for Windows and Mac guy who only has used Java. I am not asking you to do it for me, not at all, just tell me what to do. I am a total NEWB so the terminology is foreign to me.

I have watched some videos and they assume too much.

Hope I was clear. Pardon my lack of understanding!
 
This isn't a programming question, but given the OT, I assume there are quite a few CS grads in here. I'm hoping someone can help me out.

I'm going to be starting at my local university this fall for a degree in Computer Science, and I potentially have the opportunity to receive $5k a year of tuition reimbursement through my employer. However, I need to explain to them how my CS degree will be job-related and beneficial to the company. They normally only offer this to people getting a degree in Mechanical Engineering, Chemical Engineering, and business.

About the company I work: they are a leading provider of mission-critical manufacturing support services and contamination detection and protection products to the semiconductor, microelectronic, and solar industries.

Basically, we clean used engineering equipment. Any advice on what I can say to show how my degree is beneficial to the company? I hate asking for help on this, but I'm at a loss for what to say.

Thanks :)

Do you guys do any work on embedded systems?

Do any of you guys have recommendations for sites or tutorials on integrating web services with iOS apps? It seems like every job interview I go to they want to talk to me about how I would make http requests and RESTful interfaces and JSON and I've mostly worked on games and interactives that don't require internet stuff.
 
Pluralsight is pretty good, although they have a slight preference towards Microsoft products. Still, plenty of courses focus on other technologies, and they also offer courses to help career development with courses on for example interviewing, job hunting or LinkedIn usage and such.

Cool, I'll have to check it out.
 

wolfmat

Confirmed Asshole
Bit of a request.

I have never used Linux before. Ever.
I am taking an Operating Systems class that wants us to write a Hello, World program in Kernel Module. Writing in Bash was no problem. However, this kernel stuff is tough for a newcomer.

If anyone is available to help me, I can offer some type of compensation. I know, very simple for Linux guys- but tough for Windows and Mac guy who only has used Java. I am not asking you to do it for me, not at all, just tell me what to do. I am a total NEWB so the terminology is foreign to me.

I have watched some videos and they assume too much.

Hope I was clear. Pardon my lack of understanding!
Google "kernel module programming 101"

First link should be a walkthrough for your homework, other links go more into depth.
 

0xCA2

Member
Just told an honor society I could build a website for them even though I only really know basic CSS/HTML and JS (did an intro to web dev class a while back). What else would I need to know to properly build a website in 2015? They pretty much just want it to have info and pictures, so I could technically do it with what I know but I want to know what the best practices would be. What should I use?
 
Bit of a request.

I have never used Linux before. Ever.
I am taking an Operating Systems class that wants us to write a Hello, World program in Kernel Module. Writing in Bash was no problem. However, this kernel stuff is tough for a newcomer.

If anyone is available to help me, I can offer some type of compensation. I know, very simple for Linux guys- but tough for Windows and Mac guy who only has used Java. I am not asking you to do it for me, not at all, just tell me what to do. I am a total NEWB so the terminology is foreign to me.

I have watched some videos and they assume too much.

Hope I was clear. Pardon my lack of understanding!
I've had this sitting in my inbox for a few months. I haven't jumped into it yet, but if you can't find the help you need there's this and Kernel Newbies to get started.

Just told an honor society I could build a website for them even though I only really know basic CSS/HTML and JS (did an intro to web dev class a while back). What else would I need to know to properly build a website in 2015? They pretty much just want it to have info and pictures, so I could technically do it with what I know but I want to know what the best practices would be. What should I use?
The web dev Gaf thread would be able to help you more, but from following it you might want to look into Javascript libraries like Angular and figure out hosting solutions. I'm no web developer though.
 

Nelo Ice

Banned
So how are these subscription based websites like Treehouse for someone who likes to continue to improve their skills and keep up with new trends? I hear great things about it for those who want to learn who know nothing (Jon Snow).

I have heard good things about Upcase, how are they?

I'm currently using Treehouse and I'm one of those who started from knowing nothing. Though I'm still subbed, I've stopped actively watching videos since I'm attempting to build a web page from scratch. And I've gotta say I'm either stupid or the learning curve for CSS is steep lol. It's taking me awhile to get my head around positioning and sizing.

Also never heard of Upcase and Pluralsight. Right now my main issue with Treehouse is I've learned the basics and how most HTML and CSS work but not how to use it in a practical way. Like Treehouse hasn't been of much use in helping me get a project off the ground. I've had to look elsewhere and learn on my own for that. Otherwise I would have just continued taking courses without any actual work to show for it besides the step for step code I learned on Treehouse.
 
I'm currently using Treehouse and I'm one of those who started from knowing nothing. Though I'm still subbed, I've stopped actively watching videos since I'm attempting to build a web page from scratch. And I've gotta say I'm either stupid or the learning curve for CSS is steep lol. It's taking me awhile to get my head around positioning and sizing.

Nah, IMO CSS just kind of sucks. I don't work on UI every day or even every couple weeks, but I've done a bit here and there over the years. I still find myself like ....duhhh how do I do this again?

UI kits like Bootstrap make a lot of positioning related BS stupid easy now. I'd start with something like that if you're able.
 

Nelo Ice

Banned
Nah, IMO CSS just kind of sucks. I don't work on UI every day or even every couple weeks, but I've done a bit here and there over the years. I still find myself like ....duhhh how do I do this again?

UI kits like Bootstrap make a lot of positioning related BS stupid easy now. I'd start with something like that if you're able.

Yeah was curious if I should just say fuck it and start with a framework like bootstrap or learn flexbox rather than straight CSS. Since yeah right now I'm banging my head against the wall trying to position things and I'm still guessing on the right %, em, px etc for all my elements lol.

So should I drop straight CSS for now? Goal is to become a front-end web dev since design isn't really my thing since I'm terrible with photoshop and all that jazz. Am open to trying other languages though I was told learn and master html/css/javascript as a base then go on from there.

Going the self-taught route since college is expensive and my local CC only offers an intro C++ class.
 

zeemumu

Member
Quick basic question. What should I do if I need to change the value of an integer or array in the main method using a different method.
 
I'm currently using Treehouse and I'm one of those who started from knowing nothing. Though I'm still subbed, I've stopped actively watching videos since I'm attempting to build a web page from scratch. And I've gotta say I'm either stupid or the learning curve for CSS is steep lol. It's taking me awhile to get my head around positioning and sizing.

Also never heard of Upcase and Pluralsight. Right now my main issue with Treehouse is I've learned the basics and how most HTML and CSS work but not how to use it in a practical way. Like Treehouse hasn't been of much use in helping me get a project off the ground. I've had to look elsewhere and learn on my own for that. Otherwise I would have just continued taking courses without any actual work to show for it besides the step for step code I learned on Treehouse.

That's the thing about programming. Every problem is completely different. Even if they showed you how to build something and put all the pieces together into a finished product, it would be inapplicable to almost anything else you could do. You wouldn't understand why X was the right tool for the job, or the tradeoffs from choosing Y or Z, or gluing stuff together in a different way.

The bottom up approach is best. Learn how stuff works, then you can figure out anything. Yes, the figuring out part is hard, but that's why programmers get paid. There's a reason companies want experience more than education. Because experience means you've done stuff. And doing stuff is where you get the real education.
 

injurai

Banned
I'm starting to have epiphanies over just how small 1GB of ram is for a single program. Let alone 4 for all your applications, the os, your development tools and the program itself.

8 or 16GB. Anything that doesn't scale in it's memory footprint linearly or logarithmically just is not benefited much over the recent years. Shame the limitations in size and speed in relation to ram and cache.
 
Quick basic question. What should I do if I need to change the value of an integer or array in the main method using a different method.

Depends on the language. If you're using C/C++, how would you change the value of something, say int variable, within the function without using variable?
 

NotBacon

Member
Quick basic question. What should I do if I need to change the value of an integer or array in the main method using a different method.

Look up passing by reference vs passing by value.
C/C++ has pointers, C# has ref/out, Java doesn't really have that explicit pattern lol.
 

Nelo Ice

Banned
That's the thing about programming. Every problem is completely different. Even if they showed you how to build something and put all the pieces together into a finished product, it would be inapplicable to almost anything else you could do. You wouldn't understand why X was the right tool for the job, or the tradeoffs from choosing Y or Z, or gluing stuff together in a different way.

The bottom up approach is best. Learn how stuff works, then you can figure out anything. Yes, the figuring out part is hard, but that's why programmers get paid. There's a reason companies want experience more than education. Because experience means you've done stuff. And doing stuff is where you get the real education.

Experience is why I've put watching videos on hold in favor actually building something myself. But I get you mean. I just wish I could find more help on sizing and spacing since I'm kinda just putting random px, % etc in the css until it looks right. I kinda understand the theory but when I get lost whenever I use it in practice even if it makes complete sense when I've had it explained to me. That and i'm having a grand time trying to figure out how to place everything where I want it to be lol. Otherwise I'm kinda starting to make sense of how everything comes together from looking at old code and looking at other web sites and their code.

Besides those issues I am actually having fun learning and figuring out stuff. And Treehouse is the first learning tool I've tried that actually helped make sense of programming. Since last year I thought I programming was for me but gave up since I got stuck in a coursera python course. Then I tried traditional schooling and my teacher was useless and expected me to type up c++ without explaining well anything. I tried reading books but nothing clicked. I'm glad I currently having something presentable but I won't be satisfied until the page is responsive and everything looks right including making sure my code is nice and organized with comments, spacing etc.
 

Slavik81

Member
This isn't a programming question, but given the OT, I assume there are quite a few CS grads in here. I'm hoping someone can help me out.

I'm going to be starting at my local university this fall for a degree in Computer Science, and I potentially have the opportunity to receive $5k a year of tuition reimbursement through my employer. However, I need to explain to them how my CS degree will be job-related and beneficial to the company. They normally only offer this to people getting a degree in Mechanical Engineering, Chemical Engineering, and business.

About the company I work: they are a leading provider of mission-critical manufacturing support services and contamination detection and protection products to the semiconductor, microelectronic, and solar industries.

Basically, we clean used engineering equipment. Any advice on what I can say to show how my degree is beneficial to the company? I hate asking for help on this, but I'm at a loss for what to say.

Thanks :)
It's valuable to have people who understand software development. Knowing how software is designed and built, you may be able to identify areas where potential cost savings could be realized through automation.

If the development task is small enough, you may even be able to do it yourself.
 
So should I drop straight CSS for now? Goal is to become a front-end web dev since design isn't really my thing since I'm terrible with photoshop and all that jazz. Am open to trying other languages though I was told learn and master html/css/javascript as a base then go on from there..

No, don't. If you work on the front-end, you will need CSS. Even if you pick up a pre-processed flavor such as LESS (http://lesscss.org/) or SASS (http://sass-lang.com/) you will still need to grasp the basic concept of CSS and grasp it very well. No amount of frameworks will save you there, unless you want each and every site of yours look like the default Bootstrap theme. If the designers do the layout for you in Photoshop, you can't do that without CSS. If the designers do the layout in HTML/CSS, where does that put you? I guess you can do away with just JavaScript dev'ign, but still you are heavily gimped there when you have to interact with any of the DOM elements.

There's a general web dev thread here that can hel you out when you run into troubles: http://www.neogaf.com/forum/showthread.php?t=756776
 
That's the thing about programming. Every problem is completely different. Even if they showed you how to build something and put all the pieces together into a finished product, it would be inapplicable to almost anything else you could do. You wouldn't understand why X was the right tool for the job, or the tradeoffs from choosing Y or Z, or gluing stuff together in a different way.

The bottom up approach is best. Learn how stuff works, then you can figure out anything. Yes, the figuring out part is hard, but that's why programmers get paid. There's a reason companies want experience more than education. Because experience means you've done stuff. And doing stuff is where you get the real education.

This so much.
 

Nelo Ice

Banned
No, don't. If you work on the front-end, you will need CSS. Even if you pick up a pre-processed flavor such as LESS (http://lesscss.org/) or SASS (http://sass-lang.com/) you will still need to grasp the basic concept of CSS and grasp it very well. No amount of frameworks will save you there, unless you want each and every site of yours look like the default Bootstrap theme. If the designers do the layout for you in Photoshop, you can't do that without CSS. If the designers do the layout in HTML/CSS, where does that put you? I guess you can do away with just JavaScript dev'ign, but still you are heavily gimped there when you have to interact with any of the DOM elements.

There's a general web dev thread here that can hel you out when you run into troubles: http://www.neogaf.com/forum/showthread.php?t=756776

I've asked for help there a few times haven't gotten any responses for my recent issues though. And thanks for the advice. I'll stick to it.

Btw I followed the styleguide you linked me along with another and my code looks a lot cleaner than the trainwreck my css was for my first attempt.
 

Ambitious

Member
I'm working on a JPA/Hibernate assignment for an university lecture right now. The first main task is to map a few predefined classes and their relationships using JPA annotations. The project template includes a bunch of unit tests which verify that the correct tables, columns and constraints exist (though the tests do not check all possible edge cases).

I'm almost done with this part, but I really wonder how I could debug my mappings apart from executing the tests. What's the best way to see the generated schema (and if possible, even the table content)? I wrote a small method which displays all table and column names using the information_schema.tables view, but surely there must be a better way.


Related question:
The project template included stubs for all entitities and corresponding interfaces. For instance, there's a Person class implementing IPerson. One of its members is of the type IAddress, obviously implemented by Address. The address consists of a city, a street and a zip code.
Now, the address is supposed to be embedded. So I've annotated the field with @Embedded and the Address class with @Embeddable. However, when I print the schema as described above, the address columns are missing from the Person table. I've learned from a thread in the lecture forum that in this particular case, the member variable needs to be Address instead of IAddress*. When I change this, the three address columns show up in the Person table.

I've written the following test:
Code:
@Test
  public void testAddressEmbedded() {
    IAddress address = modelFactory.createAddress();
    address.setCity("city1");
    address.setStreet("street1");
    address.setZipCode("zip1");

    IModerator m = new Moderator();
    m.setFirstName("John");
    m.setLastName("Doe");
    m.setAddress(address);

    EntityTransaction tx = entityManager.getTransaction();
    tx.begin();
    entityManager.persist(m);
    entityManager.flush();
    tx.commit();

    IModerator mod = daoFactory.getModeratorDAO().findById(m.getId());

    assertEquals("John", mod.getFirstName());
    assertEquals("Doe", mod.getLastName());
    assertEquals("city1", mod.getAddress().getCity());
    assertEquals("street1", mod.getAddress().getStreet());
    assertEquals("zip1", mod.getAddress().getZipCode());
}

The weird thing is: It works. Even when I use IAddress, and the Person table consequently does not have any address fields, this works. Why?
When I modify the address object right after the commit (e.g. address.setCity("asd")), mod.getAddress().getCity() returns "asd". Why? The mod object and its address are supposed to be loaded from the database, so why does mod reference the old address object?


* The correct solution would be to annotate the IAddress field with Hibernates @Target annotation. But in the mapping subtask of the assignment, we're restricted to using only javax.persistence annotations.
 
Experience is why I've put watching videos on hold in favor actually building something myself. But I get you mean. I just wish I could find more help on sizing and spacing since I'm kinda just putting random px, % etc in the css until it looks right. I kinda understand the theory but when I get lost whenever I use it in practice even if it makes complete sense when I've had it explained to me. That and i'm having a grand time trying to figure out how to place everything where I want it to be lol. Otherwise I'm kinda starting to make sense of how everything comes together from looking at old code and looking at other web sites and their code.

Besides those issues I am actually having fun learning and figuring out stuff. And Treehouse is the first learning tool I've tried that actually helped make sense of programming. Since last year I thought I programming was for me but gave up since I got stuck in a coursera python course. Then I tried traditional schooling and my teacher was useless and expected me to type up c++ without explaining well anything. I tried reading books but nothing clicked. I'm glad I currently having something presentable but I won't be satisfied until the page is responsive and everything looks right including making sure my code is nice and organized with comments, spacing etc.

Stack overflow is a great place for getting those very specific types of questions answered .
 

zeemumu

Member
Look up passing by reference vs passing by value.
C/C++ has pointers, C# has ref/out, Java doesn't really have that explicit pattern lol.

Depends on the language. If you're using C/C++, how would you change the value of something, say int variable, within the function without using variable?

I have to work with Java. Here's the gist of it: I have a variable declared in the main method. That variable is declared by keyboard input, which works fine. But I made a method that sets that variable(or is supposed to) to a different number. Let's say the person put in the number 5 for x, and I make a method that changes whatever is in x to 13. How would I go about doing that? I can't just make an x in the method because that only changes the variable for that method, not the whole program. I could take it out of the method and make it as part of the main program but I don't think I'm able to.
 

injurai

Banned
I have to work with Java. Here's the gist of it: I have a variable declared in the main method. That variable is declared by keyboard input, which works fine. But I made a method that sets that variable(or is supposed to) to a different number. Let's say the person put in the number 5 for x, and I make a method that changes whatever is in x to 13. How would I go about doing that? I can't just make an x in the method because that only changes the variable for that method, not the whole program. I could take it out of the method and make it as part of the main program but I don't think I'm able to.

Pass x into the function as a parameter, than have it return the new value.
x = fn(x);
Shouldn't that be all you need?

If you instead make a size 1 array to hold x, you can pass the array and update the element. In which case you would then be updating that value globally.
 

zeemumu

Member
Pass x into the function as a parameter, than have it return the new value.
x = fn(x);
Shouldn't that be all you need?

If you instead make a size 1 array to hold x, you can pass the array and update the element. In which case you would then be updating that value globally.

Tested and it runs! Thanks!

I'll probably come back here with questions.
 

Nelo Ice

Banned
Stack overflow is a great place for getting those very specific types of questions answered .

Thanks, I usually end up at that place when googling just never thought to sign up. I usually search everywhere to find an answer before asking. And usually I just ask here or on the Treehouse forums.
 

Staab

Member
Bit of a mixed programming / Maths question here but I'm at a loss :

I have 5 variables with this condition : a + b + c + d + e = 1
with a > b, b > c, c > d, d > e and e >= 0.05.

How do I go about automating a program ( or Excel? I've tried the solver with no luck) that randomly generates these numbers for me ?
 
Bit of a mixed programming / Maths question here but I'm at a loss :

I have 5 variables with this condition : a + b + c + d + e = 1
with a > b, b > c, c > d, d > e and e >= 0.05.

How do I go about automating a program ( or Excel? I've tried the solver with no luck) that randomly generates these numbers for me ?

Better to write this as a single inequality chain, much easier to understand. So you've got two conditions:

1) 0.05 <= e < d < c < b < a
2) a + b + c + d + e = 1

Pseudocode:
Code:
e = random_double(0.0, 0.05)
d = random_double(e, e + (1.0 - e)/4)
c = random_double(d, d + (1.0 - d)/3)
b = random_double(c, c + (1.0 - c)/2)
a = 1.0 - b
 

Staab

Member
Better to write this as a single inequality chain, much easier to understand. So you've got two conditions:

1) 0.05 <= e < d < c < b < a
2) a + b + c + d + e = 1

Pseudocode:
Code:
e = random_double(0.0, 0.05)
d = random_double(e, e + (1.0 - e)/4)
c = random_double(d, d + (1.0 - d)/3)
b = random_double(c, c + (1.0 - c)/2)
a = 1.0 - b

I'm not sure I understand your pseudo code completely :
e is a random double between 0 and 0.05 (should be >0.05 but < d)
d between e and e+(1-e)/4
c between d and d+(1-d)/3
b between c and c+(1-c)/2
a is 1 - b ?
Wouldn't that just mean a + b = 1 and defeat the purpose of the second condition ?

Edit : I think I fixed it by changing the maximum values to sums ! Thanks for pointing me in the right direction :D
Code:
e = random_double(0.05, 0.15)
d = random_double(e, e + (1.0 - e)/4)
c = random_double(d, d + (1.0 - (d+e))/3)
b = random_double(c, c + (1.0 - (c+d+e))/2)
a = 1.0 - (b+c+d+e)
 

JeTmAn81

Member
Better to write this as a single inequality chain, much easier to understand. So you've got two conditions:

1) 0.05 <= e < d < c < b < a
2) a + b + c + d + e = 1

Pseudocode:
Code:
e = random_double(0.0, 0.05)
d = random_double(e, e + (1.0 - e)/4)
c = random_double(d, d + (1.0 - d)/3)
b = random_double(c, c + (1.0 - c)/2)
a = 1.0 - b

Your pseudocode looks like it's setting e to a number between 0 and 0.05 when the problem specifies it should be >= 0.05, but other than that this solution makes sense to me.

edit: also, yeah a = 1.0 - b at the end doesn't make sense either. A is supposed to be bigger than b. Maybe just back up your division increments to go 5, 4, 3, 2 for d, c, b, a rather than not using one for a.
 
I'm not sure I understand your pseudo code completely :
e is a random double between 0 and 0.05 (should be >0.05 but < d)
d between e and e+(1-e)/4
c between d and d+(1-d)/3
b between c and c+(1-c)/2
a is 1 - b ?
Wouldn't that just mean a + b = 1 and defeat the purpose of the second condition ?

Ahh sorry you're right. Let's try this again:
1) 0.05 <= e < d < c < b < a
2) a + b + c + d + e = 1

We can deduce e < 0.2 because if e >= 0.2, then d, c, b, a are > 0.2 and a+b+c+d+e > 1

So

Code:
e = random_double(0.05, 0.2)

After e is chosen, you now can change the conditions:

1) e < d < c < b < a
2) a + b + c + d = 1-e

So we can now deduce d < (1-e)/4 for the same reason we could deduce e < 1/5.

More generally, if you have a_1 < a_2 < ... < a_n and a_1 + a_2 + ... + a_n=S, then for each k from 1 to n, a_k < S/n
We can use this to get all the rest of the values.
Code:
d = random_double(e, (1-e)/4)
c = random_double(d, (1-e-d)/3)
b = random_double(c, (1-e-d-c)/2)
a = 1-e-d-c-b

Hopefully I got it right this time.

Edit: An example run of this algorithm might be like this:

e = random_double(0.05, 0.2) = 0.1634
d = random_double(0.1634, (1 - 0.1634)/4) = random_double(0.1634, 0.20915) = 0.2012
c = random_double(0.2012, (1 - 0.1634 - 0.2012)/3) = random_double(0.2012, 0.2118) = 0.2101
b = random_double(0.2101, (1 - 0.1634 - 0.2012 - 0.2101)/2) = random_double(0.2101, 0.21265) = 0.2113
a = 1 - .1634 - .2012 - .2101 - .2113 = 0.2140

0.05 <= 0.1634 < 0.2012 < 0.2101 < 0.2113 < 0.2140
 

JeTmAn81

Member
Ahh sorry you're right. Let's try this again:
1) 0.05 <= e < d < c < b < a
2) a + b + c + d + e = 1

We can deduce e < 0.2 because if e >= 0.2, then d, c, b, a are > 0.2 and a+b+c+d+e > 1

So

Code:
e = random_double(0.05, 0.2)

After e is chosen, you now can change the conditions:

1) e < d < c < b < a
2) a + b + c + d = 1-e

So we can now deduce d < (1-e)/4 for the same reason we could deduce e < 1/5. So

Code:
d = random_double(e, (1-e)/4)

Continuing in this fashion, we have:

Code:
c = random_double(d, (1-e-d)/3)
b = random_double(c, (1-e-d-c)/2)
a = 1-e-d-c-b

Hopefully I got it right this time.

Edit: An example run of this algorithm might be like this:

e = random_double(0.05, 0.2) = 0.1634
d = random_double(0.1634, (1 - 0.1634)/4) = random_double(0.1634, 0.20915) = 0.2012
c = random_double(0.2012, (1 - 0.1634 - 0.2012)/3) = random_double(0.2012, 0.2118) = 0.2101
b = random_double(0.2101, (1 - 0.1634 - 0.2012 - 0.2101)/2) = random_double(0.2101, 0.21265) = 0.2113
a = 1 - .1634 - .2012 - .2101 - .2113 = 0.2140

0.05 <= 0.1634 < 0.2012 < 0.2101 < 0.2113 < 0.2140

I coded this up and the algorithm will work as long as your random number generator is non-inclusive of the range. My version is range inclusive (my number generator I just Googled for) and most of the time it generates a correct result but I wrote some unit tests and after I changed the testing times from 1000 to 10,000 it started finding some invalid results.
 
I coded this up and the algorithm will work as long as your random number generator is non-inclusive of the range. My version is range inclusive (my number generator I just Googled for) and most of the time it generates a correct result but I wrote some unit tests and after I changed the testing times from 1000 to 10,000 it started finding some invalid results.

Sounds like floating point precision errors. I think the only way around this is to define an error threshold that you're satisfied with losing values in that range, and shrinking the range by that amount at each step.

so when you compute e, for example, at the next stage you don't use random_double(e, (1-e)/4), you use random_double(e+epsilon, (1-e)/4). I can't really think of a better way to handle that (with any algorithm)

Edit: Just kidding, apparently you can use nextafter! Crisis averted

Edit 2: You still might get floating point precision errors during the calculations of the the upper bound of the range. To handle that, you can clamp the result of that expression for example like b = random_double(c, std::max(c, (1-e-d-c)/2))

Edit 3: Also you didn't say what programming language you're using, but if it's C++ make sure you're using std::uniform_real_distribution
 

Staab

Member
Thanks for the help, I was really stumbling against a wall there and you showed me the way ;)

I'll try to implement it over the week-end and report back if something is amiss.

Using php, by the way, should be easy enough using mt_rand() !
 
Thanks for the help, I was really stumbling against a wall there and you showed me the way ;)

I'll try to implement it over the week-end and report back if something is amiss.

Using php, by the way, should be easy enough using mt_rand() !

Ahh, so I think you will want a function that converts an mt_rand() into a double. Probably something like this:

Code:
public function random_double($min, $max)
{
    $value = mt_rand()
    $result_normalized = $value / mt_getrandmax()

    return ($max - $min) * $result_normalized
}

But be careful! In order to guarantee that the strict inequality is met (i.e. that each number will always be *greater* than the previous), you will need access to the raw value of mt_rand(). So you could make it return that too.


Code:
public function random_double($min, $max)
{
    $value = mt_rand()
    $result_normalized = $value / mt_getrandmax()

    return array( ($max - $min) * $result_normalized, $value)
}

This way in the code that calls random_double(), you can get the "next" double by adding 1 to $value and dividing by mt_getrandmax() again. This verifies that you're generating each random number in a half-open interval, and not a closed interval.

Note: I've never written a line of PHP in my life, I have no idea if that's correct.
 

Qurupeke

Member
Not sure if this the right thread but here we go.

I'm interested in buying an Arduino. I've been learning C for 5-6 months now and I'm moving to C++ soon. Does the investment on an arduino worth it and will it be a good way to practice?
 
Not sure if this the right thread but here we go.

I'm interested in buying an Arduino. I've been learning C for 5-6 months now and I'm moving to C++ soon. Does the investment on an arduino worth it and will it be a good way to practice?

I think so, yeah. If you just want to improve your programming skills, there's probably more efficient ways, but an Arduino is a lot of fun because you can actually see something you programmed do something other than spit out some numbers on a terminal screen. I bought one a couple of months ago and I can definitely recommend the starter kit, it's really well put together. The guide is quite good.
 
Arduinos are cool, I bought a starter kit one time to research some stuff for a person well known for education software. It was for the Uno, but the Leonardo and other variants are also quite capable. It's mostly uploading firmware as C programs through Arduino's own simplified IDE and writing up hardware experiments with breadboards.

There are ways you can interface with that through Node.js or Processing with a simple firmware program that simulates a read-eval-print loop, if you're interested.

Specifically for practicing C or C++, the newer Raspberry Pi might be a better investment. Those devices run a capable Linux, and the path to SSHing to a device to send and receive files and compile programs on the device is well documented at this point.

Their biggest limitation in the past has been that the X11 based GUI is reaaaally sloooooow, and the proposed Wayland based replacement has taken awhile to find its feet. So you might be happier using it mostly from the command line and getting familiar with that. Besides that, it's one of the nicest Linux devices I've ever used, and the community around it in the official forums is super friendly. And you have just enough digital and analog pins to do Arduino-type breadboard work, too.
 

Qurupeke

Member
I see. A Raspberry pi was the first thing that I thought but it will probably be somewhat more expensive, that's why I'm inclining towards arduino. Thanks for the answers, people. I'll probably order one starter kit one of these days.
 

alatif113

Member
Need some help here for a very clean solution to the following problem:

I want to sense directional movement using two sequential PIR motion sensors where a sensor outputs 1 if triggered and 0 otherwise. So for a full pass to occur, the dual sensors need to exhibit the following state transitions

Direction 1: 00 <-> 01 <-> 11 <-> 10 <-> 00
Direction 2: 00 <-> 10 <-> 11 <-> 01 <-> 00

The system is allowed to traverse both back and forth in the above patterns. So the following will be a valid pass for direction 1

00 01 11 01 11 01 11 10 10 00

All this will need to be done in real time so I need the code to be as streamlined as possible. Any ideas?
 

Two Words

Member
I'm almost done getting this project done in my Computer Science I class. Spring Break is just starting and a lot of students are in for a rude awakening for starting it late. It's been really tough, and I really feel like it's something a bit too tough for a computer science class just past fundamental programming. Here's the project:

The program functions as a ticket purchasing program. There are 3 files that represent 3 theaters. The files only have # and . in them. A # is an empty seat, and a . is an already reserved seat. Each theater will have two linked lists, a linked list for available seats and a linked list of reserved seats (two linked lists are used to make it more difficult). So that is a total of 6 linked lists. The nodes have a payload of two integers that contain the row/column coordinate for the seat. The program, main menu has 4 options. Buy seats, display theaters, print sales reports, quit (and update the files before closing). The user can keep buying tickets as much as they want, but a single order of multiple seats must involve ordering contiguous seats and on the same row. Buying seats will move the nodes from the available linked list to the reserved linked list. If the seats they requested are not available, but there are available seats on the row that meet the amount they need, the program should suggest the seats for the user. It should suggest the seats which are available and closest to the middle such that the middle seat of the amount of seats they need is closest to the middle of the row.

The difficulty of this program is that we had a very short lesson on linked lists and we're having to handle a project on them while the lecture has moved on to classes and object oriented programming. I can't tell you how many null pointer errors I've run into. I've gotten to the point now where I haven't found any bugs yet except I can't make it properly suggest the best alternative seat if what the user requests is unavailable.
 

maeh2k

Member
Need some help here for a very clean solution to the following problem:

I want to sense directional movement using two sequential PIR motion sensors where a sensor outputs 1 if triggered and 0 otherwise. So for a full pass to occur, the dual sensors need to exhibit the following state transitions



The system is allowed to traverse both back and forth in the above patterns. So the following will be a valid pass for direction 1



All this will need to be done in real time so I need the code to be as streamlined as possible. Any ideas?

Sounds like a finite state machine would lead to a clean implementation.
 
Do developers in other countries program in their native language, or is English universal? Like, would a developer in Japan type "string" in English or Kanji?
 
Do developers in other countries program in their native language, or is English universal? Like, would a developer in Japan type "string" in English or Kanji?
I know someone who had an experience with the Nintendo DS SDK, and apparently much of the documentation was in Japanese. I don't recall if that extended to kernel level functions also being in some form of romanized Japanese, but it might have. Wouldn't surprise me.

My experience has been, thanks to the 7 bit ASCII encoding being a sort-of universal encoding thanks to C string literal specifications, standards bodies and friends, that Japanese programmers working with Unix-like tools will try to maintain some use of the english language in their stuff. You may still see the occasional bit of "romaji" crop up in function names. :)

As counter examples, the Ruby language still maintains some level of readable english throughout, and so too is Masahiro Sano's work demonstrating advanced uses of LLVM in Linux.

Another example: Kashiwagi Motiko's simplified C compiler frontend for LLVM has lots of comments and documentation in Japanese (UTF8 encoding, I assume), but the function and method names are still in english.
 

Water

Member
Do developers in other countries program in their native language, or is English universal? Like, would a developer in Japan type "string" in English or Kanji?

Programming language keywords, standard library facilities (which "string" would be in most languages) etc. are in English no matter what, they aren't translated. What differs is whether devs name their own variables, functions, classes etc. in English, whether code comments are in English, and whether other technical documentation is in English.
In Finland all reasonable developers write at least their code in English, often comments and other documentation too. Obviously devs in some other areas like Japan are less likely to be decent at English, but on the other hand, are big enough that they can afford to work in a way that isn't as compatible with the outside world.
 
Top Bottom